Search code examples
pythondjangopytestcoverage.pypytest-django

"... && 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 test src && coverage report

It'd run the tests then display the .coverage generated by coverage run ... after running.

After installing pytest-django and setting up pytest.ini, I've updated my command to:

coverage run --omit='src/manage.py,src/config/*,*/.venv/*,*/*__init__.py,*/tests.py,*/admin.py' -m pytest && coverage report

Note, I'm not using pytest-cov just yet.

For some reason I can't figure out, the coverage report is not being displayed after the tests run.

I can run each commands separately:

  • The coverage run ... runs the tests and generates the report.
  • The coverage report displays the report.

I just can't get the report to display doing ... && coverage report after switching to pytest-django.

Any reason for this?

Versions:

coverage = "^6.2"
pytest-django = "^4.7.0"

Solution

  • Per the comments, I ended up just making it two separate commands.

    In my Dockerfile:

    ...
    RUN coverage run --omit='src/manage.py,src/config/*,*/.venv/*,*/*__init__.py,*/tests.py,*/admin.py,*/migrations/*,*/apps.py' -m pytest -m=ut
    RUN coverage report -m
    ...
    

    And running in the containers with devspace:

    ...
          onUpload:
            exec:
              - command: |
                  coverage run --omit='src/manage.py,src/config/*,*/.venv/*,*/*__init__.py,*/tests.py,*/admin.py,*/migrations/*,*/apps.py' -m pytest -m=ut
                  coverage report -m
    ...