test_ok2/testing/python
Ran Benita 0dc0360351 python: fix instance handling in static and class method tests
and also fixes a regression in pytest 8.0.0 where `setup_method` crashes
if the class has static or class method tests.

It is allowed to have a test class with static/class methods which
request non-static/class method fixtures (including `setup_method`
xunit-fixture). I take it as a given that we need to support this
somewhat odd scenario (stdlib unittest also supports it).

This raises a question -- when a staticmethod test requests a bound
fixture, what is that fixture's `self`?

stdlib unittest says - a fresh instance for the test.

Previously, pytest said - some instance that is shared by all
static/class methods. This is definitely broken since it breaks test
isolation.

Change pytest to behave like stdlib unittest here.

In practice, this means stopping to rely on `self.obj.__self__` to get
to the instance from the test function's binding. This doesn't work
because staticmethods are not bound to anything.

Instead, keep the instance explicitly and use that.

BTW, I think this will allow us to change `Class`'s fixture collection
(`parsefactories`) to happen on the class itself instead of a class
instance, allowing us to avoid one class instantiation. But needs more
work.

Fixes #12065.
2024-03-09 19:35:54 +02:00
..
approx.py Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff 2024-02-02 09:27:00 +01:00
collect.py [ruff] Activate use next(iter(x)) instead of list(x)[0] and fix issue 2024-02-02 15:18:38 +01:00
fixtures.py python: fix instance handling in static and class method tests 2024-03-09 19:35:54 +02:00
integration.py python: fix instance handling in static and class method tests 2024-03-09 19:35:54 +02:00
metafunc.py Revert "testing: temporarily disable test due to hypothesis issue (#11836)" 2024-02-07 22:13:23 +02:00
raises.py [flake8-bugbear] Fixes a B017 we can actually fix and noqa the two others 2024-02-04 19:27:23 +01:00
show_fixtures_per_test.py add feature to view fixture source location in invocations with --fixtures-per-test option (#8626) 2021-05-14 14:38:55 +02:00