-
-
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
Updated docs: Now we can use environment variable PYTEST_VERSION to detect if a code is run by a pytest run #12153
Conversation
50dbb4c
to
1c96e8e
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.
The import check is actually a more fragile version a it also triggers whenever valid pytest Import was done
I recommend listing the import check as naive and the Hook based one as robust
c5fdc62
to
72db23c
Compare
1afa3f7
to
6cfd0c2
Compare
Also sorry for too much force pushes |
Converting to draft to see if there is a better way to check if a code is running from within pytest. |
Thanks @dheerajck, but I think the docs as is already shows a robust solution, why show an alternative (checking "pytest" in |
I dont want to add The approach in doc doesnt work in every case, this issue mentions one case where it doesnt work
I think we should add an env for this purpose like mentioned in that issue by @The-Compiler |
if maintainers would like to have that I can create a PR for that |
👍 by me! I understand the concerns from @RonnyPfannschmidt in #9502 (comment):
While I agree in principle to avoid adding easy ways for people to do the wrong thing, in this case I think we should add this because:
For this reason I think we should go for it. |
In that case I propose introducing a get-current-testrun-state kind of helper that return details like current item, current phase, stats as immutable entity |
But one of the requirements is to not having to import |
yes, I would suggest to not force importing pytest in non ut codes I have added a pr for this change #12190 |
@dheerajck thanks for updating it. But now that we have |
yes, I will update the docs with new changes |
Hi sorry, kinda busy as I started to look for a new job |
Done @nicoddemus |
…rom within a pytest run
…is running from within a pytest run
…within a pytest run
Thanks @dheerajck! |
Add a better way to detect if a code is running from within a pytest run.