-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python properties on test classes are executed during test collection #2234
Comments
bluetech
added a commit
to bluetech/pytest
that referenced
this issue
Feb 5, 2017
Previously, properties such as in the added test case were triggered during collection, possibly executing unintended code. Let's skip them instead. We should probably skip all custom descriptors, however I am not sure how to do this cleanly, so for now just skip properties. Fixes pytest-dev#2234.
bluetech
added a commit
to bluetech/pytest
that referenced
this issue
Feb 6, 2017
Previously, properties such as in the added test case were triggered during collection, possibly executing unintended code. Let's skip them instead. We should probably skip all custom descriptors, however I am not sure how to do this cleanly, so for now just skip properties. Fixes pytest-dev#2234.
bluetech
added a commit
to bluetech/pytest
that referenced
this issue
Feb 7, 2017
Descriptors (e.g. properties) such as in the added test case are triggered during collection, executing arbitrary code which can raise. Previously, such exceptions were propagated and failed the collection. Now these exceptions are caught and the corresponding attributes are silently ignored. A better solution would be to completely skip access to all custom descriptors, such that the offending code doesn't even trigger. However I think this requires manually going through the instance and all of its MRO for each and every attribute checking if it might be a proper fixture before accessing it. So I took the easy route here. In other words, putting something like this in your test class is still a bad idea...: @Property def innocent(self): os.system('rm -rf /') Fixes pytest-dev#2234.
This was referenced Mar 14, 2017
This was referenced Mar 6, 2018
2 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A test suite with a test file such as the following fails during test collection:
I expect the property (or other types of custom descriptors) to not be executed during collection.
For comparison, unittest, from which I am migrating, does not execute properties (unless the tests use them of course).
pip list
of the virtual environment you are usingThe text was updated successfully, but these errors were encountered: