MCPcopy
hub / github.com/pytest-dev/pytest / _register_setup_module_fixture

Method _register_setup_module_fixture

src/_pytest/python.py:569–601  ·  view source on GitHub ↗

Register an autouse, module-scoped fixture for the collected module object that invokes setUpModule/tearDownModule if either or both are available. Using a fixture to invoke this methods ensures we play nicely and unsurprisingly with other fixtures (#517).

(self)

Source from the content-addressed store, hash-verified

567 return super().collect()
568
569 def _register_setup_module_fixture(self) -> None:
570 """Register an autouse, module-scoped fixture for the collected module object
571 that invokes setUpModule/tearDownModule if either or both are available.
572
573 Using a fixture to invoke this methods ensures we play nicely and unsurprisingly with
574 other fixtures (#517).
575 """
576 setup_module = _get_first_non_fixture_func(
577 self.obj, ("setUpModule", "setup_module")
578 )
579 teardown_module = _get_first_non_fixture_func(
580 self.obj, ("tearDownModule", "teardown_module")
581 )
582
583 if setup_module is None and teardown_module is None:
584 return
585
586 def xunit_setup_module_fixture(request) -> Generator[None]:
587 module = request.module
588 if setup_module is not None:
589 _call_with_optional_argument(setup_module, module)
590 yield
591 if teardown_module is not None:
592 _call_with_optional_argument(teardown_module, module)
593
594 fixtures.register_fixture(
595 # Use a unique name to speed up lookup.
596 name=f"_xunit_setup_module_fixture_{self.obj.__name__}",
597 func=xunit_setup_module_fixture,
598 node=self,
599 scope="module",
600 autouse=True,
601 )
602
603 def _register_setup_function_fixture(self) -> None:
604 """Register an autouse, function-scoped fixture for the collected module object

Callers 1

collectMethod · 0.95

Calls 1

Tested by

no test coverage detected