pytest-coverage

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
The goal is for the tests to cover all lines of code.
Generate a coverage report with:
pytest --cov --cov-report=annotate:cov_annotate
If you are checking for coverage of a specific module, you can specify it like this:
pytest --cov=your_module_name --cov-report=annotate:cov_annotate
You can also specify specific tests to run, for example:
pytest tests/test_your_module.py --cov=your_module_name --cov-report=annotate:cov_annotate
Open the cov_annotate directory to view the annotated source code. There will be one file per source file. If a file has 100% source coverage, it means all lines are covered by tests, so you do not need to open the file.
For each file that has less than 100% test coverage, find the matching file in cov_annotate and review the file.
If a line starts with a ! (exclamation mark), it means that the line is not covered by tests. Add tests to cover the missing lines.
Keep running the tests and improving coverage until all lines are covered.
我们的目标是让测试覆盖所有代码行。
使用以下命令生成覆盖率报告:
pytest --cov --cov-report=annotate:cov_annotate
如果你要检查特定模块的覆盖率,可以这样指定:
pytest --cov=your_module_name --cov-report=annotate:cov_annotate
你也可以指定要运行的特定测试,例如:
pytest tests/test_your_module.py --cov=your_module_name --cov-report=annotate:cov_annotate
打开cov_annotate目录查看带注释的源代码。 每个源文件对应一个注释文件。如果某个文件的代码覆盖率达到100%,说明所有行都被测试覆盖,无需打开该文件。
对于每个测试覆盖率低于100%的文件,在cov_annotate中找到对应的文件并查看。
如果某一行以!(感叹号)开头,说明该行未被测试覆盖。 添加测试来覆盖这些未覆盖的行。
持续运行测试并提升覆盖率,直到所有代码行都被覆盖。