File tree Expand file tree Collapse file tree 4 files changed +64
-1
lines changed Expand file tree Collapse file tree 4 files changed +64
-1
lines changed Original file line number Diff line number Diff line change 17
17
from .settings import DEFAULT_SETTINGS
18
18
from .utils import seq
19
19
20
- pytest_plugins = ["tests.plugins.django_modeladmin" ]
20
+ pytest_plugins = [
21
+ "tests.plugins.django_modeladmin" ,
22
+ "tests.plugins.integration" ,
23
+ ]
21
24
22
25
23
26
def pytest_configure (config ):
Original file line number Diff line number Diff line change
1
+ from __future__ import annotations
2
+
3
+ import pytest
4
+
5
+
6
+ def test_automatically_skip ():
7
+ pytest .fail ("tests in `integration` directory should be automatically skipped" )
Original file line number Diff line number Diff line change
1
+ from __future__ import annotations
2
+
3
+ from pathlib import Path
4
+
5
+ import pytest
6
+
7
+ MARK = "integration"
8
+ CLI_FLAG = "--integration"
9
+
10
+
11
+ def pytest_addoption (parser : pytest .Parser ) -> None :
12
+ """Add the --integration flag to pytest CLI.
13
+
14
+ Args:
15
+ parser: pytest parser.
16
+ """
17
+ parser .addoption (
18
+ CLI_FLAG , action = "store_true" , help = "run integration tests as well"
19
+ )
20
+
21
+
22
+ def pytest_configure (config : pytest .Config ) -> None :
23
+ """Add the integration marker to pytest config.
24
+
25
+ Args:
26
+ config: pytest config.
27
+ """
28
+ config .addinivalue_line ("markers" , f"{ MARK } : mark tests as integration tests" )
29
+
30
+
31
+ def pytest_runtest_setup (item : pytest .Item ) -> None :
32
+ """Do not run tests marked as integration tests by default, unless a flag is set.
33
+
34
+ Args:
35
+ item: pytest's test item.
36
+ """
37
+ if MARK in item .keywords and not item .config .getoption (CLI_FLAG ):
38
+ pytest .skip (f"pass { CLI_FLAG } to run integration tests" )
39
+
40
+
41
+ def pytest_collection_modifyitems (
42
+ config : pytest .Config , items : list [pytest .Item ]
43
+ ) -> None :
44
+ """Marks tests in the integration folder as end-to-end tests (which will not run by default).
45
+
46
+ Args:
47
+ config: pytest configuration.
48
+ items: Items to test (individual tests).
49
+ """
50
+ integration_dir = Path (__file__ ).parent .parent / "integration"
51
+ for item in items :
52
+ if Path (item .fspath ).parent == integration_dir :
53
+ item .add_marker (MARK )
You can’t perform that action at this time.
0 commit comments