Questions tagged [pytest-cov]

pytest-cov is a pytest plugin which produces coverage reports the same way as coverage does, but with better support for pytest and integrated support for coverage in subprocesses. It also works with pytest-xdist. All configuration options provided by coverage are supported.

Reference:

120 questions
45
votes
2 answers

How to get coverage reporting when testing a pytest plugin?

Context I am updating an inherited repository which has poor test coverage. The repo itself is a pytest plugin. I've changed the repo to use tox along with pytest-cov, and converted the "raw" tests to use pytester as suggested in the pytest…
Thomas Thorogood
  • 2,150
  • 3
  • 24
  • 30
45
votes
7 answers

import file mismatch in pytest

I've got a file in the package with 'test' in its name and when I run pytest I got an error import file mismatch: imported module 'my_project.my_file_test' has this __file__ attribute: …
vZ10
  • 2,468
  • 2
  • 23
  • 33
16
votes
1 answer

Coverage.py Vs pytest-cov

The documentation of coverage.py says that Many people choose to use the pytest-cov plugin, but for most purposes, it is unnecessary. So I would like to know what is the difference between these two? And which one is the most efficient ? Thank you…
yosra
  • 702
  • 1
  • 11
  • 24
16
votes
3 answers

WARNING: Failed to generate report: No data to report error in python using pytest module

sample.py def sum(num1, num2): return num1 + num2 def sum_only_positive(num1, num2): if num1 > 0 and num2 > 0: return num1 + num2 else: return None test_sample.py from . import sample import pytest def test_sum(): …
12
votes
1 answer

codecov unable to collect data using pytest - "Coverage.py warning: No data was collected."

I'm trying to setup codecov on my public travis repo and so far haven't been able to successfully generate a report and upload it to codecov.io. I appear to receive an erroneous report in terminal that says 0% of my code is covered along with a…
Frozenglass
  • 145
  • 1
  • 9
10
votes
1 answer

How can I use pytest-cov to both generate a coverage report and also print to terminal?

Background I'm new to using pytest and pytest-cov having switched over from unittest + coverage.py I first set up my automated tests to run in this way: python3 -m pytest --cov=myapplication which gave me output like this to the…
sunyata
  • 1,843
  • 5
  • 27
  • 41
9
votes
1 answer

Pytest cov does not read pyproject.toml

Pytest cov is not reading its setting from the pyproject.toml file. I am using nox, so I run the test with: python3 -m nox It seems I have the same issue even without nox. In fact, after running a poetry install: poetry run pytest --cov=src passes…
user1315621
  • 3,044
  • 9
  • 42
  • 86
8
votes
1 answer

Python project code coverage badge with coveralls / github actions

I'm trying to add a code coverage % badge to my repos README.md I'm currently using Github actions to automate my pytest testing. I had that working on its own, but ive been struggling trying to get the coverage % badge. I am using coveralls for…
matthewmturner
  • 566
  • 7
  • 21
8
votes
1 answer

Python: ImportError: No module named _pluggy

I am getting ImportError: No module named _pluggy error when running tests using pytest. Then I tried installing pluggy using pip install pluggy. It installs pluggy==0.6.0 successfully, but is still giving the error. Versions List (From running…
Pubudu Dodangoda
  • 2,742
  • 2
  • 22
  • 38
7
votes
1 answer

Implementing code coverage and unit testing on existing Python/Flask app

Having trouble getting this implementation down. What I need: Code coverage results on my existing flask application, preferably using unit tests compatible with pytest. What I am seeing: I am seeing coverage only for lines that are executed on the…
Liquidmetal
  • 275
  • 6
  • 22
6
votes
2 answers

Running pytest-cov along with pytest in VS Code

I'm trying to make it so that when I run my test in test explorer it will automatically generate a cov.xml file at the same time in the project folder. Ive tried adding in the arguments to the pytest argument field on VS Code but it does not seem to…
Sam T
  • 81
  • 1
  • 5
6
votes
1 answer

Missing test coverage pytest python class

I am testing my code with pytest --cov but one of my modules gets 0% coverage. The module has one class declaration as such: class DataBaseMaker: @staticmethod def create_database(): conn = sqlite3.connect("database.db") …
Franz
  • 235
  • 3
  • 14
5
votes
1 answer

Pytest-Cov Show Coverage For Untouched Files

When I run my tests, I realised that pytest-cov only shows coverage reports for files that are touched during the automated tests. How can I set it so that it shows coverage for even files that are not touched?
Daniel
  • 67
  • 1
  • 7
5
votes
2 answers

What is pytest result mean?

I'm learning about testing in Python, and now I'm using pytest-cov. I try to run this command: pytest --cov=myProj tests/ --cov-report term-missing after the testing done I got the report like this: ----------- coverage: platform linux,…
Tri
  • 2,722
  • 5
  • 36
  • 65
5
votes
1 answer

Unit test coverage with GitLab CI

I'm trying to set up a unit test coverage tool for one of the Python projects. I managed to script the GitLab CI YML file, but it runs into errors when triggered. Here is the error that I get: ImportError while importing test module…
joesan
  • 13,963
  • 27
  • 95
  • 232
1
2 3 4 5 6 7 8