forked from pytest-dev/pytest
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
User request
Starting v6.2.0, unittest setUpClass fixtures are no longer "private"
Minimal example:
import unittest
class Tests(unittest.TestCase):
@classmethod
def setUpClass(cls):
pass
def test_1(self):
pass
$ pytest --fixtures
...
unittest_setUpClass_fixture_Tests [class scope] -- .../site-packages/_pytest/unittest.py:145
... no docstring available
Expected behavior: generated fixtures should be private (prefixed with underscore) unless -v is used.
Additional context: Also affects xunit setup/teardown fixtures; likely introduced in PRs 7990, 7931, 7929. Proposed fix: prefix generated fixture names with '_'.
Researcher specification
Summary
- Internal autouse fixtures generated for unittest/xunit setup/teardown began appearing as public in
pytest --fixturessince 6.2.0. These should be hidden by default (shown only with-v) by prefixing their names with_.
Scope and locations
- src/_pytest/unittest.py
- Function: _make_xunit_fixture (around line ~147)
- Current pattern: name=f"unittest_{setup_name}fixture{obj.qualname}"
- Change to: name=f"unittest{setup_name}fixture{obj.qualname}"
- src/_pytest/python.py
- Module._inject_setup_module_fixture (around ~531)
- Change name to: f"xunit_setup_module_fixture{self.obj.name}"
- Module._inject_setup_function_fixture (around ~560)
- Change name to: f"xunit_setup_function_fixture{self.obj.name}"
- Class._inject_setup_class_fixture (around ~812)
- Change name to: f"xunit_setup_class_fixture{self.obj.qualname}"
- Class._inject_setup_method_fixture (around ~841)
- Change name to: f"xunit_setup_method_fixture{self.obj.qualname}"
- Module._inject_setup_module_fixture (around ~531)
Rationale
- The fixture listing code hides fixtures with a leading underscore unless
-vis used. Prefixing the generated names restores expected behavior without changing functionality.
Tests to add
- New tests under testing/python/test_unittest_xunit_fixture_visibility.py to assert that:
- Default
pytest --fixturesdoes not show these internal fixtures. pytest --fixtures -vdoes show them with leading underscores.- Similarly for
--fixtures-per-testdefault vs-v. - Cover unittest setUpClass and xunit setup at module/class/method levels.
- Default
Reproduction
- Before change: create a unittest.TestCase with setUpClass and a module with setup_module; run
pytest --fixturesand observe public names likeunittest_setUpClass_fixture_*andxunit_setup_module_fixture_*. - After change: those names are suppressed by default and visible with
-vonly.
Notes
- Behavior change likely introduced in PRs 7990/7931/7929 timeframe (pytest 6.2.0).
- No behavioral changes to test execution; only fixture display names.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels