Skip to content

Commit 3cf5e38

Browse files
authored
Merge pull request #220 from tornaria/__test__
dont run repeated tests from cython __test__ dict
2 parents 95ed336 + 114c999 commit 3cf5e38

File tree

1 file changed

+8
-25
lines changed

1 file changed

+8
-25
lines changed

src/conftest.py

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
from _pytest.nodes import Collector
55
from _pytest.doctest import DoctestModule
66

7+
from _pytest.pathlib import resolve_pkg_root_and_module_name
8+
import importlib
9+
710
# cysignals-CSI only works from gdb, i.e. invoke ./testgdb.py directly
811
collect_ignore = ["cysignals/cysignals-CSI-helper.py"]
912

@@ -24,30 +27,10 @@ def pytest_collect_file(
2427
config = parent.config
2528
if file_path.suffix == ".pyx":
2629
if config.option.doctestmodules:
30+
# import the module so it's available to pytest
31+
_, module_name = resolve_pkg_root_and_module_name(file_path)
32+
module = importlib.import_module(module_name)
33+
# delete __test__ injected by cython, to avoid duplicate tests
34+
del module.__test__
2735
return DoctestModule.from_parent(parent, path=file_path)
2836
return None
29-
30-
31-
# Need to import cysignals to initialize it
32-
import cysignals # noqa: E402
33-
34-
try:
35-
import cysignals.alarm
36-
except ImportError:
37-
pass
38-
try:
39-
import cysignals.signals
40-
except ImportError:
41-
pass
42-
try:
43-
import cysignals.pselect
44-
except ImportError:
45-
pass
46-
try:
47-
import cysignals.pysignals
48-
except ImportError:
49-
pass
50-
try:
51-
import cysignals.tests # noqa: F401
52-
except ImportError:
53-
pass

0 commit comments

Comments
 (0)