Skip to content

Commit 606a629

Browse files
committed
Cleanup temporary hidden variable too
and use "___" instead of the more commonly used "_" to avoid any potential naming collisions. Tweak `test_requires_module_variable` to check that no output is returned too.
1 parent 3188e5b commit 606a629

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

pytest_doctestplus/plugin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -930,10 +930,10 @@ def _prepend_importorskip(self, test, *, module):
930930
"""Prepends `pytest.importorskip` before the doctest."""
931931
source = (
932932
"import pytest; "
933-
# Hide output of this statement in `_`, otherwise doctests fail
934-
f"_ = pytest.importorskip({module!r}); "
933+
# Hide output of this statement in `___`, otherwise doctests fail
934+
f"___ = pytest.importorskip({module!r}); "
935935
# Don't impact what's available in the namespace
936-
"del pytest"
936+
"del pytest; del ___"
937937
)
938938
importorskip = doctest.Example(source=source, want="")
939939
test.examples.insert(0, importorskip)

tests/test_doctestplus.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,10 @@ def g():
15671567

15681568
def test_requires_module_variable(testdir):
15691569
p = testdir.makepyfile("""
1570-
__doctest_requires__ = {("f",): ["module_that_is_not_availabe"]}
1570+
__doctest_requires__ = {
1571+
("f",): ["module_that_is_not_availabe"],
1572+
("g",): ["pytest"],
1573+
}
15711574
15721575
def f():
15731576
'''

0 commit comments

Comments
 (0)