Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

conftest.py 2.5 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  1. # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
  2. import shutil
  3. from pathlib import Path
  4. from tests import TMP
  5. def pytest_addoption(parser):
  6. """Add custom command-line options to pytest."""
  7. parser.addoption("--slow", action="store_true", default=False, help="Run slow tests")
  8. def pytest_collection_modifyitems(config, items):
  9. """
  10. Modify the list of test items to exclude tests marked as slow if the --slow option is not specified.
  11. Args:
  12. config: The pytest configuration object that provides access to command-line options.
  13. items (list): The list of collected pytest item objects to be modified based on the presence of --slow option.
  14. """
  15. if not config.getoption("--slow"):
  16. # Remove the item entirely from the list of test items if it's marked as 'slow'
  17. items[:] = [item for item in items if "slow" not in item.keywords]
  18. def pytest_sessionstart(session):
  19. """
  20. Initialize session configurations for pytest.
  21. This function is automatically called by pytest after the 'Session' object has been created but before performing
  22. test collection. It sets the initial seeds and prepares the temporary directory for the test session.
  23. Args:
  24. session: The pytest session object.
  25. """
  26. from ultralytics.utils.torch_utils import init_seeds
  27. init_seeds()
  28. shutil.rmtree(TMP, ignore_errors=True) # Delete any existing tests/tmp directory
  29. TMP.mkdir(parents=True, exist_ok=True) # Create a new empty directory
  30. def pytest_terminal_summary(terminalreporter, exitstatus, config):
  31. """
  32. Cleanup operations after pytest session.
  33. This function is automatically called by pytest at the end of the entire test session. It removes certain files
  34. and directories used during testing.
  35. Args:
  36. terminalreporter: The terminal reporter object used for terminal output.
  37. exitstatus (int): The exit status of the test run.
  38. config: The pytest config object.
  39. """
  40. from ultralytics.utils import WEIGHTS_DIR
  41. # Remove files
  42. models = [path for x in {"*.onnx", "*.torchscript"} for path in WEIGHTS_DIR.rglob(x)]
  43. for file in ["decelera_portrait_min.mov", "bus.jpg", "yolo11n.onnx", "yolo11n.torchscript"] + models:
  44. Path(file).unlink(missing_ok=True)
  45. # Remove directories
  46. models = [path for x in {"*.mlpackage", "*_openvino_model"} for path in WEIGHTS_DIR.rglob(x)]
  47. for directory in [WEIGHTS_DIR / "path with spaces", TMP.parents[1] / ".pytest_cache", TMP] + models:
  48. shutil.rmtree(directory, ignore_errors=True)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...