CarinaTheBookworm
CarinaTheBookworm

Reputation: 185

Is Python 3.9.6 compatible with pytest 6.2.5?

I am trying to test views and models for Django REST API written in pycharm and have installed pytest for this. I have written some tests and when I wanted to start them I got the following error message:

ERROR: usage: _jb_pytest_runner.py [options] [file_or_dir] [file_or_dir] [...]
_jb_pytest_runner.py: error: unrecognized arguments: --cov=frontend --cov-report=html

I have then checked if I have installed pytest properly and it seems I have. I have both Python 2.7.16 as well as Python 3.9.6 installed but am using Python 3. Could this be a compatibility problem or is it something else?

I have tried starting the tests both through the terminal using py.test and just in the IDE itself. I keep getting this same error message.

I have tried the approach below:

py.test: error: unrecognized arguments: --cov=ner_brands --cov-report=term-missing --cov-config

yet I seem to get the same error.

ERROR: usage: _jb_pytest_runner.py [options] [file_or_dir] [file_or_dir] [...]
_jb_pytest_runner.py: error: unrecognized arguments: --cov=frontend --cov-report=html

Does anyone know how I could solve this issue?

Thanks in advance.

Upvotes: 1

Views: 2032

Answers (1)

Michael Mintz
Michael Mintz

Reputation: 15526

First of all, yes, Python 3.9.6 is compatible with pytest 6.2.5, however, you appear to be missing a few dependencies. pytest is one of many different Python packages, and you appear to have installed that successfully, so you're halfway there.

There are a few different coverage plugins that work with pytest, and those need to be installed separately. Here are the two most common coverage plugins for Python and pytest:

https://pypi.org/project/coverage/

https://pypi.org/project/pytest-cov/

The first one, coverage is installed with:

pip install coverage

The second one, pytest-cov is installed with:

pip install pytest-cov

Based on your run command, you appear to want to use pytest-cov. After you've installed that, you can verify that pytest has those new options by calling pytest --help:

> pytest --help

...
coverage reporting with distributed testing support:
  --cov=[SOURCE]        Path or package name to measure during execution (multi-allowed). Use --cov= to
                        not do any source filtering and record everything.
  --cov-reset           Reset cov sources accumulated in options so far.
  --cov-report=TYPE     Type of report to generate: term, term-missing, annotate, html, xml (multi-
                        allowed). term, term-missing may be followed by ":skip-covered". annotate, html
                        and xml may be followed by ":DEST" where DEST specifies the output location.
                        Use --cov-report= to not generate any output.
  --cov-config=PATH     Config file for coverage. Default: .coveragerc
  --no-cov-on-fail      Do not report coverage if test run fails. Default: False
  --no-cov              Disable coverage report completely (useful for debuggers). Default: False
  --cov-fail-under=MIN  Fail if the total coverage is less than MIN.
...

Alternatively, you might be able to get the same results you're looking for using coverage:

coverage run -m pytest

coverage html

coverage report

And that will also give you a coverage report even if not using pytest-cov options.

Upvotes: 1

Related Questions