-
-
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
Clean up state after in process pytest runs #3016
Clean up state after in process pytest runs #3016
Conversation
0e6ce01
to
79c80a0
Compare
79c80a0
to
3e98082
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jurko-gospodnetic, this looks like a nice cleanup!
I think this should go into features
though as it might break test suites which use pytester
, like it did happen with pytest's own test suite.
I don't have time to make a more in depth review right now (I should be in bed already), hopefully I will have more time tomorrow.
Thanks again!
changelog/3016.bugfix
Outdated
@@ -0,0 +1,7 @@ | |||
internal pytest test suite improvements: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we can have sub-items in newsfiles
like this because it will break up the RST lint checker. You can run inv changelog
to update the changelog and check it yourself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took a while to figure out what inv changelog
meant or how to get it working for the project. You really should add a tox environment for this and add a note in the contributing docs on how to run all these processes.
needed to:
- figure out where the change log is generated from
- what
invoke
was - what I need to have installed to run it
- what arguments to pass to invoke
in the end, the best way seems to have been:
- create an environment
- install the packages from tasks/requirements.txt
- run
towncrier --draft
to see the generated changelog in the console output without anything else getting modified in the project
@nicoddemus - as for targeting the But I'll move it to |
5acf160
to
35aa325
Compare
@nicoddemus - now rebased on top of the |
@jurko-gospodnetic thanks for retargeting the branch. I understand your point of view, but we do our best to avoid breaking existing test suites even if they are working by accident. 👍 |
I will review this as soon as I have some time, thanks for all the hard work you put into this, we appreciate it! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @jurko-gospodnetic!
|
||
# Any sys.module or sys.path changes done while running py.test | ||
# inline should be reverted after the test run completes to avoid | ||
# clashing with later inline tests run within the same pytest test, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
fc6dc4d
to
d7f3007
Compare
|
Now extracted to new CwdSnapshot, SysModulesSnapshot & SysPathsSnapshot classes, each saving the state they are interested in on instantiation and restoring it in its `restore()` method.
Now each in-process pytest run saves a snapshot of important global Python state and restores it after the test completes, including the list of loaded modules & the Python path settings. Previously only the loaded package data was getting restored, but that was also reverting any loaded package changes done in the test triggering the pytest runs, and not only those done by the pytest runs themselves. Updated acceptance tests broken by this change, which were only passing before by accident as they were making multiple pytest runs with later ones depending on sys.path changes left behind by the initial one.
d7f3007
to
d85a3ca
Compare
well done ! thanks |
Internal pytest test suite improvements:
Testdir
taking snapshots & restoring global Python state - extracted to newCwdSnapshot
,SysModulesSnapshot
&SysPathsSnapshot
classes, each saving the state they are interested in on instantiation and restoring it in itsrestore()
methodsys.path
changes left behind by the initial oneChanges:
_pytest/pytested.py
- main changetesting/acceptance_test.py
- updated + slightly improved broken teststesting/deprecated_test.py
- updated broken testtesting/test_pytester.py
- improved existing tests including added tests for the new functionality