Skip to content

Commit cbe3e3e

Browse files
authored
[custom] conftest: add "integration" mark for tests to be run manually (#61)
They are slow, and it makes not even sense to run them on CI all the time.
1 parent 9081ee9 commit cbe3e3e

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

testing/conftest.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33

44
import pytest
55

6+
7+
def pytest_addoption(parser):
8+
parser.addoption(
9+
"--run-integration-tests", action="store_true", help=("Run integration tests.")
10+
)
11+
12+
613
if sys.gettrace():
714

815
@pytest.fixture(autouse=True)
@@ -17,6 +24,23 @@ def restore_tracing():
1724
sys.settrace(orig_trace)
1825

1926

27+
@pytest.hookimpl
28+
def pytest_runtest_setup(item):
29+
mark = "integration"
30+
option = "--run-integration-tests"
31+
if mark not in item.keywords or item.config.getoption(option):
32+
return
33+
34+
# Run the test anyway if it was provided via its nodeid as arg.
35+
# NOTE: do not use startswith: should skip
36+
# "tests/test_foo.py::test_bar" with
37+
# "tests/test_foo.py" in invocation args.
38+
if any(item.nodeid == arg for arg in item.config.invocation_params.args):
39+
return
40+
41+
pytest.skip("Not running {} test (use {})".format(mark, option))
42+
43+
2044
@pytest.hookimpl(hookwrapper=True, tryfirst=True)
2145
def pytest_collection_modifyitems(config, items):
2246
"""Prefer faster tests.

testing/test_meta.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import _pytest
66
import pytest
77

8+
pytestmark = [pytest.mark.integration, pytest.mark.slow]
9+
810

911
def _modules():
1012
return sorted(
@@ -15,7 +17,6 @@ def _modules():
1517
)
1618

1719

18-
@pytest.mark.slow
1920
@pytest.mark.parametrize("module", _modules())
2021
def test_no_warnings(module):
2122
# fmt: off

testing/test_modimport.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import _pytest
77
import pytest
88

9-
pytestmark = pytest.mark.slow
9+
pytestmark = [pytest.mark.integration, pytest.mark.slow]
1010

1111
MODSET = [
1212
x

tox.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ markers =
163163
baz
164164
# conftest.py reorders tests moving slow ones to the end of the list
165165
slow
166+
# tests to be run only on CI (slow, unlikely to be a problem normally)
167+
integration
166168
# experimental mark for all tests using pexpect
167169
uses_pexpect
168170

0 commit comments

Comments
 (0)