简体   繁体   中英

How to ignore / omit / exclude files during test coverage?

In order to get 100% test coverage, I need to ignore some file(s) in python.

I searched the web and I found nosetests which I don't want to use.

I also found that I can edit my .coveragerc file and omit files and functions, when running my tests using intellij (with unittest framework), it didn't manage to use .coveragerc file.

Any idea how to ignore / omit / exclude files during test coverage?

How can I run the test using this file as a parameter?

You can use this command in your .coveragerc file.

# .coveragerc
[report]
show_missing = True
omit =
    junk/*

You include the path of files you want to omit under the omit command, for example, I want to omit every file in the junk folder hence my use of junk/* .

To add to proton's answer .

You can also use the # pragma: no cover commenting specific clauses. You can comment every clause in a file to exclude the content of the file. This is more tedious but gives you finer control if you want to partially ignore a file.

Here is a link to the coverage.py project that discuses coverage exclusion in further detail: https://coverage.readthedocs.io/en/7.0.0/excluding.html


I would have commented on proton's answer instead of making a new answer, but I do not have enough reputation. More so, I would have suggested an edit, but there are too many pending edits and stack-overflow will not let me add another.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM