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.9 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
  1. # Ultralytics YOLO 🚀, AGPL-3.0 license
  2. import shutil
  3. from pathlib import Path
  4. from tests import TMP
  5. def pytest_addoption(parser):
  6. """
  7. Add custom command-line options to pytest.
  8. Args:
  9. parser (pytest.config.Parser): The pytest parser object for adding custom command-line options.
  10. Returns:
  11. (None)
  12. """
  13. parser.addoption("--slow", action="store_true", default=False, help="Run slow tests")
  14. def pytest_collection_modifyitems(config, items):
  15. """
  16. Modify the list of test items to exclude tests marked as slow if the --slow option is not specified.
  17. Args:
  18. config (pytest.config.Config): The pytest configuration object that provides access to command-line options.
  19. items (list): The list of collected pytest item objects to be modified based on the presence of --slow option.
  20. Returns:
  21. (None) The function modifies the 'items' list in place, and does not return a value.
  22. """
  23. if not config.getoption("--slow"):
  24. # Remove the item entirely from the list of test items if it's marked as 'slow'
  25. items[:] = [item for item in items if "slow" not in item.keywords]
  26. def pytest_sessionstart(session):
  27. """
  28. Initialize session configurations for pytest.
  29. This function is automatically called by pytest after the 'Session' object has been created but before performing
  30. test collection. It sets the initial seeds and prepares the temporary directory for the test session.
  31. Args:
  32. session (pytest.Session): The pytest session object.
  33. Returns:
  34. (None)
  35. """
  36. from ultralytics.utils.torch_utils import init_seeds
  37. init_seeds()
  38. shutil.rmtree(TMP, ignore_errors=True) # delete any existing tests/tmp directory
  39. TMP.mkdir(parents=True, exist_ok=True) # create a new empty directory
  40. def pytest_terminal_summary(terminalreporter, exitstatus, config):
  41. """
  42. Cleanup operations after pytest session.
  43. This function is automatically called by pytest at the end of the entire test session. It removes certain files
  44. and directories used during testing.
  45. Args:
  46. terminalreporter (pytest.terminal.TerminalReporter): The terminal reporter object used for terminal output.
  47. exitstatus (int): The exit status of the test run.
  48. config (pytest.config.Config): The pytest config object.
  49. Returns:
  50. (None)
  51. """
  52. from ultralytics.utils import WEIGHTS_DIR
  53. # Remove files
  54. models = [path for x in ["*.onnx", "*.torchscript"] for path in WEIGHTS_DIR.rglob(x)]
  55. for file in ["bus.jpg", "yolo11n.onnx", "yolo11n.torchscript"] + models:
  56. Path(file).unlink(missing_ok=True)
  57. # Remove directories
  58. models = [path for x in ["*.mlpackage", "*_openvino_model"] for path in WEIGHTS_DIR.rglob(x)]
  59. for directory in [TMP.parents[1] / ".pytest_cache", TMP] + models:
  60. 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...