-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Remove sys.last_traceback attribute using del instead of setting to None #6256
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
Remove sys.last_traceback attribute using del instead of setting to None #6256
Conversation
Looks like the Travis CI failure is a result of the |
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 a lot @mdickinson!
@mdickinson What do you think about not deleting it though? I.e. it would always contain the last exception that occurred, which can be useful with |
@blueyed I'm not sure: personally, I think I prefer the deletion. At work, we have quite a lot of large (>1000 individual test methods) test suites that take some time to run (e.g., 20 minutes or more). In that situation, test interactions are one of the most costly problems: if a test passes fine by itself, but fails in the context of the larger test suite, it can take hours to track down the interactions that are causing it to fail. And one of the key ingredients in avoiding test interactions is ensuring that tests don't modify shared global state; or at least that if they do modify that state, then they restore it to its previous state before the test ends. (And the So on the one hand, if a test runner helps reset state changes, that's helpful. On the other hand, in a well-written test those state changes shouldn't be happening in the first place, so as a developer I'd quite like some kind of warning about those state changes so that I can fix the test. The core Python test runner ( |
Existing code in the test runner clears the
sys.last_traceback
,sys.last_type
andsys.last_exc
attributes by setting them toNone
. This PR changes that code to delete these attributes usingdel
instead.Rationale:
sys
module is unchanged by the test run. (Going from the attribute not existing to it existing but beingNone
is a change, albeit a fairly benign one.)del
.sys.last_traceback
(for example) to just two: either the attribute doesn't exist, or it does exist and it's a genuine traceback. AllowingNone
introduces a new third possible state that any user ofsys.last_traceback
needs to be aware of.Fixes #6255.