Skip to content

Commit 2c4d4b6

Browse files
committed
Don't import sphinxdoc.setup under its own name in the tests
pytest before 8.0 treats a module-level `setup` as an xunit setup hook and calls it once per test with the test module as its argument, so importing the extension's `setup` into the test module's namespace turned every test in the file into an error: AttributeError: module 'tests.config.test_sphinxdoc' has no attribute 'add_object_type' Only the minimum-versions job caught it, since it pins pytest 7.0 and the nose-style hooks were removed in pytest 8. Verified against pytest 7.0.1. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019qMpoL5cL6W4qCeCdGm26w
1 parent 6b89125 commit 2c4d4b6

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎tests/config/test_sphinxdoc.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414
format_aliases,
1515
interesting_default_value,
1616
reverse_aliases,
17-
setup,
1817
write_doc,
1918
)
2019

20+
# Imported under another name on purpose: pytest before 8.0 treats a
21+
# module-level `setup` as an xunit setup hook and calls it with the test
22+
# module as its argument, which fails every test in the file.
23+
from traitlets.config.sphinxdoc import setup as setup_extension
24+
2125

2226
class ExplodingInt(Int):
2327
"""An Int whose default cannot be rendered, like a trait holding an object."""
@@ -63,7 +67,7 @@ def add_object_type(self, *args, **kwargs):
6367

6468
def test_setup_registers_the_configtrait_object_type():
6569
app = StubSphinxApp()
66-
metadata = setup(app)
70+
metadata = setup_extension(app)
6771
assert app.object_types == [
6872
(("configtrait", "configtrait"), {"objname": "Config option"}),
6973
]

0 commit comments

Comments
 (0)