Skip to content

Commit 1dd6ff4

Browse files
authored
MAINT: fix a a collection error under pytest 8.1.x (#143)
pytest 8.1.0 is yanked but the change is probably worth it anyway as it tracks the pytest main as of post- 8.0.2dev
1 parent 21c2d61 commit 1dd6ff4

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

scpdt/plugin.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -182,24 +182,37 @@ class DTModule(DoctestModule):
182182
in the specified module or file.
183183
"""
184184
def collect(self):
185-
# Part of this code is copy-pasted from the `_pytest.doctest` module(pytest 7.4.0):
186-
# https://github.com/pytest-dev/pytest/blob/448563caaac559b8a3195edc58e8806aca8d2c71/src/_pytest/doctest.py#L497
187-
if self.path.name == "setup.py":
188-
return
189-
if self.path.name == "conftest.py":
190-
module = self.config.pluginmanager._importconftest(
191-
self.path,
192-
self.config.getoption("importmode"),
193-
rootpath=self.config.rootpath
194-
)
195-
else:
196-
try:
197-
module = import_path(
185+
if pytest.__version__ < '8':
186+
# Part of this code is copy-pasted from the `_pytest.doctest` module(pytest 7.4.0):
187+
# https://github.com/pytest-dev/pytest/blob/448563caaac559b8a3195edc58e8806aca8d2c71/src/_pytest/doctest.py#L497
188+
if self.path.name == "setup.py":
189+
return
190+
if self.path.name == "conftest.py":
191+
module = self.config.pluginmanager._importconftest(
198192
self.path,
199-
root=self.config.rootpath,
200-
mode=self.config.getoption("importmode"),
193+
self.config.getoption("importmode"),
194+
rootpath=self.config.rootpath
201195
)
202-
except ImportError:
196+
else:
197+
try:
198+
module = import_path(
199+
self.path,
200+
root=self.config.rootpath,
201+
mode=self.config.getoption("importmode"),
202+
)
203+
except ImportError:
204+
if self.config.getvalue("doctest_ignore_import_errors"):
205+
outcomes.skip("unable to import module %r" % self.path)
206+
else:
207+
raise
208+
209+
# XXX: `assert module == self.obj` seems to work (so is it all automatic?)
210+
# but what are failure modes
211+
else:
212+
# https://github.com/pytest-dev/pytest/blob/8.1.0/src/_pytest/doctest.py#L561
213+
try:
214+
module = self.obj
215+
except _pytest.nodes.Collector.CollectError:
203216
if self.config.getvalue("doctest_ignore_import_errors"):
204217
outcomes.skip("unable to import module %r" % self.path)
205218
else:

0 commit comments

Comments
 (0)