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

Method _register_setup_function_fixture

src/_pytest/python.py:603–637  ·  view source on GitHub ↗

Register an autouse, function-scoped fixture for the collected module object that invokes setup_function/teardown_function 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

601 )
602
603 def _register_setup_function_fixture(self) -> None:
604 """Register an autouse, function-scoped fixture for the collected module object
605 that invokes setup_function/teardown_function if either or both are available.
606
607 Using a fixture to invoke this methods ensures we play nicely and unsurprisingly with
608 other fixtures (#517).
609 """
610 setup_function = _get_first_non_fixture_func(self.obj, ("setup_function",))
611 teardown_function = _get_first_non_fixture_func(
612 self.obj, ("teardown_function",)
613 )
614 if setup_function is None and teardown_function is None:
615 return
616
617 def xunit_setup_function_fixture(request) -> Generator[None]:
618 if request.instance is not None:
619 # in this case we are bound to an instance, so we need to let
620 # setup_method handle this
621 yield
622 return
623 function = request.function
624 if setup_function is not None:
625 _call_with_optional_argument(setup_function, function)
626 yield
627 if teardown_function is not None:
628 _call_with_optional_argument(teardown_function, function)
629
630 fixtures.register_fixture(
631 # Use a unique name to speed up lookup.
632 name=f"_xunit_setup_function_fixture_{self.obj.__name__}",
633 func=xunit_setup_function_fixture,
634 node=self,
635 scope="function",
636 autouse=True,
637 )
638
639
640class Package(nodes.Directory):

Callers 1

collectMethod · 0.95

Calls 1

Tested by

no test coverage detected