Register an autouse, class scoped fixture into the collected class object that invokes setup_class/teardown_class if either or both are available. Using a fixture to invoke this methods ensures we play nicely and unsurprisingly with other fixtures (#517).
(self)
| 786 | return super().collect() |
| 787 | |
| 788 | def _register_setup_class_fixture(self) -> None: |
| 789 | class="st">"""Register an autouse, class scoped fixture into the collected class object |
| 790 | that invokes setup_class/teardown_class if either or both are available. |
| 791 | |
| 792 | Using a fixture to invoke this methods ensures we play nicely and unsurprisingly with |
| 793 | other fixtures (class="cm">#517). |
| 794 | class="st">""" |
| 795 | setup_class = _get_first_non_fixture_func(self.obj, (class="st">"setup_class",)) |
| 796 | teardown_class = _get_first_non_fixture_func(self.obj, (class="st">"teardown_class",)) |
| 797 | if setup_class is None and teardown_class is None: |
| 798 | return |
| 799 | |
| 800 | def xunit_setup_class_fixture(request) -> Generator[None]: |
| 801 | cls = request.cls |
| 802 | if setup_class is not None: |
| 803 | func = getimfunc(setup_class) |
| 804 | _call_with_optional_argument(func, cls) |
| 805 | yield |
| 806 | if teardown_class is not None: |
| 807 | func = getimfunc(teardown_class) |
| 808 | _call_with_optional_argument(func, cls) |
| 809 | |
| 810 | fixtures.register_fixture( |
| 811 | class="cm"># Use a unique name to speed up lookup. |
| 812 | name=fclass="st">"_xunit_setup_class_fixture_{self.obj.__qualname__}", |
| 813 | func=xunit_setup_class_fixture, |
| 814 | node=self, |
| 815 | scope=class="st">"class", |
| 816 | autouse=True, |
| 817 | ) |
| 818 | |
| 819 | def _register_setup_method_fixture(self) -> None: |
| 820 | class="st">"""Register an autouse, function scoped fixture into the collected class object |