Why can't coverage the data in the "if __name__ == "__main__":"
See original GitHub issuetest.py
if __name__ == "__main__":
print("hello world!")
run:pytest --cov=./ test.py
output:
----------- coverage: platform linux, python 3.9.9-final-0 -----------
Name Stmts Miss Cover
-----------------------------
test.py 2 1 50%
-----------------------------
TOTAL 2 1 50%
The normal coverage rate should be 100%. why 50%.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How to test or mock "if __name__ == '__main__'" contents
Heya, I've added a new answer that gives 100% test coverage (with tests !) and doesn't require ignoring anything. Let me know what...
Read more >What Does if __name__ == "__main__" Do in Python?
When you import your file as a module, the code that you nested under if __name__ == "__main__" doesn't execute. Now that you...
Read more >How to test if __name__ == '__main__' - Medium
How to test if __name__ == '__main__'. You need to test those two pesky lines at the end of your app, if you...
Read more >What does if __name__ == "__main__" do? - Python Engineer
When the Python interpreter reads a source file, it does two things: First, it sets a few special variables like __name__; Then it...
Read more >Python Tutorial: if __name__ == '__main__' - YouTube
... in Python: if __name__ == '__main__ ':This conditional is used to check whether a python m... ... Your browser can't play this...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Segelzwerg you’re using multiprocessing in your test suite, support for it was removed in pytest-cov 4. See the changelog for migration path: https://pytest-cov.readthedocs.io/en/latest/changelog.html
@ionelmc thanks for the advice. I didn’t realize it. Will investigate now!