简体   繁体   English

运行 pytest 和 pytest-cov 时忽略特定文件(不是目录)

[英]Ignore specific files (not directory) while running pytest and pytest-cov

I have project structure as:我的项目结构为:

myproject
 src
   -routes.py
   -services.py
   -data_access.py
 tests
   -test_routes.py
   -test_services.py

I want to run the tests with coverage on src but want to exclue src/data_access.py .我想在src上运行覆盖范围的测试,但想排除src/data_access.py

I want to implement something similar to: pytest tests --cov=src --exclude=src/data_access.py but exclude is not the right argument.我想实现类似于: pytest tests --cov=src --exclude=src/data_access.py排除不是正确的参数。

@Anu is right, but didn't fully explained. @Anu 是对的,但没有完全解释。

You need to create.coveragerc file to the root of your project.(If you don't then you need to specify where is it).您需要将 create.coveragerc 文件添加到项目的根目录。(如果您不这样做,则需要指定它的位置)。

In that file add:在该文件中添加:
[run] [跑步]
omit =./*省略 =./*
This will remove all the folders from coverage, considering that you're currently in the root of the project.考虑到您当前位于项目的根目录中,这将从覆盖范围中删除所有文件夹。
If you need to include specific files, use include =... instead.如果您需要包含特定文件,请改用 include =...。

You may need to add coveragerc and use the —omit option.您可能需要添加coveragerc 并使用--omit 选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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