21
21
def pytest_configure (config ):
22
22
"""
23
23
This hook runs before each pytest invocation. Its purpose is to handle optional fetching
24
- of remote artifacts needed for the test run. For testing, you should run one of the following:
24
+ of remote artifacts needed for the test run and filtering across unit tests, recipe tests, and
25
+ regression tests.
25
26
26
- - `pytest tests --without-integration --without-slow-integration`: run unit tests only
27
- - `pytest tests --without-slow-integration`: run unit tests and recipe tests
28
- - `pytest tests`: run all tests
27
+ When testing, you should run one of the following:
28
+
29
+ - `pytest tests`: run unit tests only
30
+ - `pytest tests --with-integration`: run unit tests and recipe tests
31
+ - `pytest tests --with-integration --with-slow-integration`: run all tests
29
32
- `pytest tests -m integration_test`: run recipe tests only
30
33
- `pytest tests -m slow_integration_test`: run regression tests only
31
34
32
- This hook ensures that the appropriate artifacts are available locally for each of these cases.
33
- It also supports optional silencing of S3 progress bars to reduce CI log spew.
35
+ Similar commands apply for filtering in subdirectories or individual test files.
36
+
37
+ This hook also ensures that the appropriate artifacts are available locally for all of the above cases.
38
+ Note that artifact download is determined by the CLI flags, so if you run e.g.
39
+ `pytest tests/torchtune/some_unit_test.py -m integration_test`, the integration test
40
+ artifacts will be downloaded even if your test doesn't require them.
41
+
42
+ The hook also supports optional silencing of S3 progress bars to reduce CI log spew via `--silence-s3-logs`.
34
43
"""
44
+
45
+ # To make it more convenient to run an individual unit test, we override the default
46
+ # behavior of pytest-integration to run with --without-integration --without-slow-integration
47
+ # This means that we need to manually override the values of run_integration and run_slow_integration
48
+ # whenever either set of tests is passed via the -m option.
49
+
50
+ if config .option .markexpr == "integration_test" :
51
+ config .option .run_integration = True
52
+ run_regression_tests = False
53
+ if config .option .markexpr == "slow_integration_test" :
54
+ config .option .run_slow_integration = True
55
+ run_recipe_tests = False
56
+
35
57
# Default is to run both integration and slow integration tests (i.e. both are None)
36
58
run_recipe_tests = (
37
59
config .option .run_integration is None or config .option .run_integration is True
@@ -41,12 +63,6 @@ def pytest_configure(config):
41
63
or config .option .run_slow_integration is True
42
64
)
43
65
44
- # For -m flags, we run only those tests and so disable the others here
45
- if config .option .markexpr == "integration_test" :
46
- run_regression_tests = False
47
- if config .option .markexpr == "slow_integration_test" :
48
- run_recipe_tests = False
49
-
50
66
cmd = str (CACHE_ARTIFACTS_SCRIPT_PATH )
51
67
52
68
if run_recipe_tests :
0 commit comments