546 questions
1
vote
0
answers
48
views
Why doesn't pytest-cov fail with a non-zero exit code when code coverage threshold isn't met, when running on multiple directories?
When the average test coverage threshold across multiple modules isn't met, pytest doesn't fail with a non-zero exit code, even though it should.
My command:
❯ pytest --cov module1 --cov module2 --cov ...
0
votes
1
answer
59
views
How do I selectively hide no-data-collected when using coverage.py?
I have a test suite that runs a bunch of system tests on an API. Some system tests interact with the API by using Flask's test_client, whereas a few specific tests interact with the API by making HTTP ...
1
vote
0
answers
108
views
Exclude methods consisting of a single pass statement from coverage reports in python
In my class, I have some methods that can be overridden by subclasses, but do not need to be.
I like to test my project and generate a coverage report using coverage.py.
Because the method of the ...
0
votes
0
answers
124
views
Coverage Discrepancies in pytest: Code Executed but Not Tracked
I discovered that when I run pytest with coverage, the coverage report shows that the tests do not fully cover the code, even though the tests execute the relevant code.
Full Coverage Command (100% ...
0
votes
0
answers
43
views
How to run globally installed coverage on a package inside a virtual enviroment?
I'd like to run a coverage check with the following configuration:
coverage is installed globally on the system (via pipx).
pytest in installed inside the virtual environment of the project.
(Inside ...
1
vote
1
answer
27
views
Exclude directory but include file in coverage.py reports?
I want to exclude tests directories, but include one file from the tests directory. Example .coveragerc:
[run]
omit =
*/tests/*
!*/myapp/tests/my_file.py
but I think coverage.py doesn't ...
0
votes
1
answer
299
views
The coverage run icon in the Test Explorer is not displayed in Visual Studio Code
The coverage run icon in the Test Explorer is not displayed in Visual Studio Code. Check snapshot. Is There a way to enable coverage on Visual Code interface?
I'm using Python pytest and working ...
0
votes
1
answer
103
views
How to Generate pytest Code Coverage Report for Manual testing without writing unit test cases
In java we can generate code coverage report for manual testing by using Jacoco agent. Want to do the same for python application. We want to run the application on server, capture the manual testing ...
0
votes
0
answers
73
views
diff-cover changes the ui of an azure devops?
So I was integrating the diff-cover tool in my repository and found that it sometimes gives in a UI format that the line was tested or not tested in the PR -> File.
Any idea how does this work?
...
-3
votes
1
answer
238
views
How to combine coverage.xml files for github action coverage report? [duplicate]
I wrote code related to a website in python. Below is my file structure,
├── app_layer
│ ├── src
│ └── tests
├── core
│ ├── src
│ └── tests
├── model
│ ├── src
│ └── tests
├── .github
│ ├...
1
vote
1
answer
114
views
coverage.py always reports one missing statement but the html report doesen't show what the missing statement is
I am using coverage.py to measure the statement/code coverage of my test.
There are two files that are being tested:
example_solution.py
created_unit_test.py
"example_solution" contains a ...
0
votes
1
answer
229
views
no-data-collected when running tests with tox but not when running tests with pytest
I'm using tox to run unit tests with pytest. When I run the tests with tox, it runs the tests and shows the tree of my src directory but prints CoverageWarning: No data was collected. (no-data-...
0
votes
0
answers
113
views
Error while running coverage run because of os.environ in python
My code is importing several variables using os.environ. When I run 'coverage run' command for testing, it gives key error. Is there a way to provide env files to read env variables from there, or ...
0
votes
1
answer
106
views
How to log coverage report to logs or summary?
I have a workflow that looks like this:
on:
push:
branches:
- master
jobs:
git_pull:
runs-on: self-hosted
steps:
- name: executing remote ssh commands
uses: appleboy/...
0
votes
0
answers
35
views
Why 'coverage' considers all of my class-based-views as tested?
I'm just learning django testing.
When I use 'Coverage' module to check which parts of my code is tested, it considers almost all of class-based-views as tested while I have commented out all of my ...
0
votes
1
answer
57
views
"... && coverage report" not working after switching to pytest-django
I was using unittest in Django to write tests and running the tests with this command:
coverage run --omit='src/manage.py,src/config/*,*/.venv/*,*/*__init__.py,*/tests.py,*/admin.py' src/manage.py ...
0
votes
1
answer
303
views
Coverage's dynamic context usage returns 'no contexts were measured'
I'm interested in seeing what test triggers what code via the coverage tool.
I followed the instruction https://coverage.readthedocs.io/en/latest/contexts.html#dynamic-contexts, to enable dynamic ...
0
votes
1
answer
962
views
Pytest reports missing lines in coverage for imports and constant assignments
I'm baffled by differences in coverage behavior for different files in my project and hope someone will please suggest how to debug this more effectively than I am doing now. This is basically the ...
22
votes
3
answers
7k
views
Azure PublishCodeCoverageResults@2 issue with detailed report for coverage
I'm trying to switch PublishCodeCoverageResults from @1 to @2. Because appeared warnig in pipeline
##[warning]New V2 version of task publishing code coverage results is available to all our customers ...
0
votes
1
answer
38
views
Limit coverage report to only listing which methods/functions were never called
Is there a way to have coverage only list functions that never get called? This is more to prune dead code than to enhance unit tests.
For example, given the following test.py, we can see that c will ...
2
votes
1
answer
340
views
Coverage of process spawned by pytest
I am trying to get coverage on a Python process spawned by pytest. Here are the steps I took:
Create a sitecustomize.py module in my local site packages directory
#/home/Olumide/.local/lib/python3....
0
votes
1
answer
75
views
coveragerc file ignores classes with similar names
I'm running a coverage report in python and i created a .coveragerc file. I have two classes for example:
class LinearRegression
class LinearRegressionMLE
when i instruct the coverage report to ...
0
votes
1
answer
901
views
How to display the right coverage for unit-tests in python?
I am having trouble displaying the correct coverage info for unittest. I created a simple python file as such: simple.py that contains the following contents:
def multiply(x, y):
return x * y
...
0
votes
1
answer
53
views
No coverage in IDE, but coveragepy shows 46% coverage
I'm trying to get code coverage metrics in my IDE, but I can't seem to get the coverage to show right. It always shows up as no coverage.
I am using the following in ~/.vim/ftplugin/ale.vim:
Plug '...
0
votes
1
answer
60
views
Cython coverage not showing properly
After any call to a Cython library, no lines show up as covered, even though I have tests that are clearly covering the library calls. I even tested this by putting in a obligatory ...
0
votes
1
answer
95
views
How to get coverage for lines following call to a Cython module
I have some code which uses a library that happens to use Cython under the hood.
I'm observing that, following any call to a Cython function in that library, no lines in my own code are picked up as ...
3
votes
0
answers
79
views
Test Coverage Does NOT Count lines coverred by Selenium Webdriver
This is a flask app with a rather simple pytest setup.
import subprocess
import time
import pytest
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
@pytest.fixture(...
-2
votes
1
answer
142
views
interpretion of branch coverage
This is kind of an followup question to How do I interpret Python coverage.py branch coverage results?
I have a different situation where I check a variable perr which has in different scenarios, ...
0
votes
1
answer
449
views
Run Tests with Coverage "TypeError: Parameters to Generic[...] must all be type variables"
When running tests with coverage using PyCharm on django (python) project, im having the following error:
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm 2023.1.2\...
0
votes
0
answers
306
views
coverage/pytest and gitlab CI not running
I am currently having two issues involving coverage/pytest and gitlab CI.
The bigger and more recent one is that pytest and coverage do nothing at all when i call them in the gitlab CI. I do not get ...
0
votes
1
answer
397
views
How do I find coverage for subprocesses under test?
Consider the following simple program:
# thingy.py
import sys
print("ready")
for line in sys.stdin:
print(line, end='')
If I want to unit-test the program, I can stub out the side-...
2
votes
1
answer
1k
views
Functional difference between `coverage run -m pytest` and `pytest --cov=...`?
The Coverage tool supports generating code coverage data from Pytest tests with coverage run -m pytest .... However, there is also the Pytest-Cov plugin, which invokes Coverage and generates coverage ...
3
votes
1
answer
1k
views
Combine coverage reports into one xml in python
my python project is composed of several different packages
main_dir
|- package_1
|- package_2
|_ package_3
i'm testing each package separately with pytest and pytest-cov
python -m pytest package_1\...
1
vote
1
answer
567
views
Pytest cov doesn't recognize option
I'm running pytest with pytest-cov with the following command line:
python -m pytest Mytools\tests --junitxml test_reports\unittest_result.xml --cov . --cov-branch --cov-report xml:test_reports\...
6
votes
1
answer
2k
views
| python coverage report error | no source for code: PATH + '/_remote_module_non_scriptable.py'
When I run coverage run -m pytest tests/ followed by coverage report in the terminal
I get the following error:
No source for code: '/private/var/.../_remote_module_non_scriptable.py'.
It seems like a ...
0
votes
1
answer
51
views
How to write coverage test case for wxpython's event.Skip()?
I am trying to increase my coverage percentage on my coverage report and there is this method that I want to write a test case for using an **assert ** statement. It is only one line, but for my test ...
3
votes
1
answer
1k
views
Coverage.py returns error "No source for code:..." when running tensorflow.keras.model.fit function
I have built unittests for my code and everything works fine when running them from vscode. Even running coverage run runs successfully.
But when I try to run coverage report I get the following ...
0
votes
0
answers
424
views
Python coverage test percentage higher than expected
Python 3.10
I'm working on my first Python project and am confused by the following output when I run
coverage run -m pytest followed by venv/bin/coverage report --show-missing. I'm specifically ...
1
vote
1
answer
8k
views
Configure pyproject.toml for unittest and coverage
I used in the pass pytest but wanted to use this time unittest instead. I use the integrated testframework from vscode and for testing it just runs fine. Further I wanted to use coverage. My structure ...
0
votes
1
answer
1k
views
How can I achieve test coverage for `ClientError` exceptions raised in my unit tests for a Python script that utilizes boto3 and moto?
I have this python script snippet with mocked aws infrastructure for a todo list application:
import os
import boto3
import time
import uuid
import json
import functools
from botocore.exceptions ...
0
votes
0
answers
147
views
Why my unit test coverage is at the lower side?
I have written a small class and function and unit test case for them.
from flask_restful import Resource
class Calculator:
def __init__(self, a, b ):
self.a = a
self.b = b
...
0
votes
3
answers
636
views
Django was unable to create a connection to the 'postgres' database and will use the first PostgreSQL database instead -Coverage
I am trying to run python tests using coverage. However, when I try to run the command, the following error appears:
$ python3 manage.py test
Creating test database for alias 'default'...
/workspace/....
-2
votes
1
answer
621
views
Python module not found with sudo in github action
I wanted to use coveragepy combine to seperate .coverage files into one.
For that I installed python and the coverage module via pip, afterwards then running this command. python -m coverage combine ....
2
votes
0
answers
1k
views
How to run code coverage to completion with the report even if pytest is failing?
We have some test cases that are known to fail: those are in our backlog to complete. The tests that fail are not consistent.
I have a separate branch that cleans this all up: but we need the coverage ...
2
votes
1
answer
1k
views
How to fix tox.ini when it keeps complaining about no module named coverage?
I am trying to send a Pull Request to an opensource library.
But I keep getting ModuleNotFoundError: No module named 'coverage'
This is the log in Github CI
Run tox -e lint,py310-dj40
lint: freeze> ...
1
vote
0
answers
258
views
Using default tool values for reusable noxfile
I am implementing a reusable noxfile, my goal is that the different Python components of my project can have the same workflow for testing, linting, etc.
To do this, I created a nox_plugin module ...
5
votes
1
answer
7k
views
Test code and branch coverage simultanously with Pytest
I am using pytest to test my Python code.
To test for code coverage (C0 coverage) I run pytest --cov and I can specify my desired coverage in my pyproject.toml file like this:
[tool.coverage.report]
...
1
vote
1
answer
824
views
Why does coverage.py not report a for loop where the body is not skipped when running it with --branch?
Consider the following example file test.py:
def fun(l):
for i in l:
a = 1
print(a)
if __name__ == '__main__':
fun([1])
Testing branch coverage with
coverage erase; coverage run -...
0
votes
2
answers
356
views
Python coverage saving files outside of docker but not inside
So I've been wanting to integrate code coverage in my tests and for that im using the coverage api.
I have a exit handler which gets triggered on SIGINT, SIGTERM and SIGABRT signals:
import logging
...
0
votes
1
answer
182
views
Disabling tf.function decorators for code coverage pytest run
As discussed here, code coverage tools do not work nicely with tensorflow due to its code transformation. One suggested workaround is to use tf.config.experimental_run_functions_eagerly(True) when ...