I am testing an application and try to determine why Coverage reports missing a line that is executed. I insolated a test for this report.
In a file called assistants.py I have the following code:
def get_project_from_assistant(request, user, requested_project, assistant):
# Get all the assistants the user has with that name across projects
num_assistants = (
request.dbsession.query(Userproject, Collaborator)
.filter(Userproject.project_id == Collaborator.project_id)
.filter(Userproject.user_id == user)
.filter(Userproject.access_type == 1)
.filter(Collaborator.coll_id == assistant)
.count()
)
print("******************************777")
print(__file__)
print("******************************777")
if num_assistants > 0:
if num_assistants == 1: # Line 302
print("******************************2222")
print("I am in line 304")
print("******************************222")
....
I run the test with "pytest -s --cov=formshare" and my .coveragerc file is as follows:
# .coveragerc to control coverage.py
[run]
branch = True
source = formshare
[paths]
source =
formshare/
*/site-packages/
[report]
show_missing = True
exclude_lines =
pragma: no cover
except
The output shows that the function get_project_from_assistant is executed many times because there are multiple calls across the source code but eventually line 304 onwards get executed:
******************************777
/home/cquiros/data/projects2017/personal/software/FormShare/formshare/processes/db/assistant.py
******************************777
******************************777
/home/cquiros/data/projects2017/personal/software/FormShare/formshare/processes/db/assistant.py
******************************777
******************************777
/home/cquiros/data/projects2017/personal/software/FormShare/formshare/processes/db/assistant.py
******************************777
******************************777
/home/cquiros/data/projects2017/personal/software/FormShare/formshare/processes/db/assistant.py
******************************777
******************************777
/home/cquiros/data/projects2017/personal/software/FormShare/formshare/processes/db/assistant.py
******************************777
******************************777
/home/cquiros/data/projects2017/personal/software/FormShare/formshare/processes/db/assistant.py
******************************777
******************************777
/home/cquiros/data/projects2017/personal/software/FormShare/formshare/processes/db/assistant.py
******************************777
******************************2222
I am in line 304
******************************222
However, this is the coverage information just for that file (I removed the rest of the lines for clarity):
I am testing an application and try to determine why Coverage reports missing a line that is executed. I insolated a test for this report.
In a file called assistants.py I have the following code:
I run the test with "pytest -s --cov=formshare" and my .coveragerc file is as follows:
The output shows that the function get_project_from_assistant is executed many times because there are multiple calls across the source code but eventually line 304 onwards get executed:
However, this is the coverage information just for that file (I removed the rest of the lines for clarity):
It says that it misses from line 302->326 but is definitely passing by 304 because of the print()
Might this problem be related to passing many times through the same file?
Using: pytest version 5.4.2 coverage version 5.1