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
Update advice about _called_from_test. #6168
Conversation
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.
as we dont have a executing example yet this is fine as is, but we should follow up with an actual execution at a later point
|
||
.. code-block:: python | ||
|
||
if hasattr(sys, "_called_from_test"): | ||
if your_module._called_from_test: | ||
# called from within a test run | ||
... | ||
else: | ||
# called "normally" | ||
... | ||
|
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 noted that we haven't yet a actual example execution block, so this example isn't actually executed demoing the effect -
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.
How do I do that?
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.
TBH I think the current example is fine, it is a really contrived use case anyways. 🤷♂
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 think this is mergeable as is but will defer clicking the button until @RonnyPfannschmidt has had additional input 👍
We should squash the commits before merging as well. |
Instead of giving an example of using sys and then, at the end, advising not to use sys, just give a correct example. This is especially helpful since mypy 0.740 has started (correctly) complaining about sys._called_from_pytest not being present.
please merge, having it as runner example take a bit of tinkering |
Instead of giving an example of using
sys
and then, at the end, advising to not usesys
, just give a preferred example. This is especially helpful since mypy 0.740 has started (correctly) complaining aboutsys._called_from_test
not being present.