Last active
October 7, 2024 20:39
-
-
Save eshirazi/f282354d8b1c21c3829f6489fea971cd to your computer and use it in GitHub Desktop.
Is Python running in unit-test mode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import inspect | |
| def is_running_unit_tests(): | |
| return any( | |
| i[1].endswith("unittest/loader.py") or | |
| i[1].endswith("unittest\\loader.py") or | |
| i[1].endswith("unittest/main.py") or | |
| i[1].endswith("unittest\\main.py") or | |
| i[1].endswith("unittest/runner.py") or | |
| i[1].endswith("unittest\\runner.py") or | |
| i[1].endswith("pytest/main.py") or | |
| i[1].endswith("pytest\\main.py") | |
| for i in inspect.stack() | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment