Comments (11)
@bluetech I think this might be similar to #12425 but wasn't entirely sure if it is same case so reported it separately.
from pytest.
Bisected to 1a5e0eb:
from pytest.
I'm not near a computer, the property issue is familiar (my first patch to pytest was fixing exactly that..), but the _
part sounds very strange, does it really not happen if you remove the _variable
assignment?
from pytest.
Right, sorry. In our code when _variable is not assigned we get exception thrown right away in code so I got wrong impression of this. Updated bug title and description. Seems just @property
is needed to reproduce it.
from pytest.
Right. So the situation is this:
- During collection, pytest needs to find fixtures (methods decorated with
@pytest.fixture
) - To do this, it scans all of the attributes of the class
- Scanning an attribute of a class, when the attribute is a property, causes it to run
This has always been an issue with non-unittest test classes. In 8.2 it also started becoming an issue for unittest classes, because we've made the unittest code consistent with the non-unittest code. Unfortunately it also exposes unittest classes to this deficiency.
The reason unittest wasn't affected previously is that it used to work like this: do the collection on the class itself, not an instance, then bind it to an instance only later. When you access the property attribute on the class itself, the property doesn't trigger.
You might ask, if the old unittest was safer, why not switch non-unittest to that instead of the other way? The reason is that it's a much more impactful change, and brings some issues of its own. For example, to which instance should a class-scoped fixture method be bound?
In general I do think collecting on the class instead of an instance is probably better, but it will need some work and breaking changes to get there.
Another fix to the issue is check if the attribute is a property before accessing it and skip it if so. @RonnyPfannschmidt has a draft PR to do it (it's the oldest open PR). Downside of that is performance overhead, breaking change, and some technical issues.
from pytest.
Related Issues (20)
- Add hooks to allow further AST customization and control pyc caching while assertion rewriting. HOT 1
- pytest_terminal_summary question 关于运行同一个例子但是结果样式不同问题 HOT 8
- log_file Does not support formatting?For example, generate the date of the day HOT 3
- Allow the user to provide the submission command that will be prepended to the PyTest command that runs individual tests HOT 5
- autouse fixtures named with a leading underscore do not run HOT 2
- text diffs on huge files are slow HOT 2
- Add a new hook to inform user of current state on signal HOT 4
- Parametrize: Substitute argvalues in ids HOT 1
- doctest expecting asserts behaves differently than stdlib
- Question about teardowns when setup fixture fails. HOT 2
- pytest 8.2.2 breaks pytest-rerunfailures for tests that inherit unittest.TestCase HOT 4
- pytest 8.2.0 regresses collection and now collects non-Test* classes HOT 4
- `pytest.mark.usefixtures()` without argument gets silently ignored HOT 4
- MockAwareDocTestFinder has stale docstring HOT 1
- MockAwareDocTestFinder._find_lineno is stale HOT 4
- MockAwareDocTestFinder._find is stale
- Pytest documentation website issue: Python code example blocks not rendering properly in pytest documentation HOT 3
- pytest 8.2.2 fails assertion HOT 1
- pytest approx wrong formatting return - printing all values as wrong.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pytest.