I'm trying to run py.test
and execute only pylint, but not unittests.
The documentation on this page indicates you can do it:
https://pypi.org/project/pytest-pylint/
You can restrict your test run to only perform pylint checks and not any other tests by typing:
py.test --pylint -m pylint
But when I run that command exactly I still get errors from unittests that py.test
found. The linting process seems to run as expected, then I get a bunch of errors in unittest files reported. This seems contrary to the documentation.
py.test --version
shows that I'm using 0.14.0
:
$ py.test --version
This is pytest version 4.0.0, imported from /usr/local/lib/python3.6/dist-packages/pytest.py
setuptools registered plugins:
pytest-pylint-0.14.0 at /usr/local/lib/python3.6/dist-packages/pytest_pylint.py
Answering on behalf of comments:
Are you getting linter errors about code style in unit tests or actual unit tests failures? – Gediminas Feb 7 at 20:12
Good question, mostly module import errors, pythonpath issues in the unittest files that, while easy to solve, aren't supposed to be run at all. We want the lint errors only in this part of the Jenkins pipeline. We will define another part of the pipeline to run unittests properly. – David Parks Feb 7 at 20:14
"> mostly module import errors, pythonpath issues in the unittest files that, while easy to solve, aren't supposed to be run at all." - I think the explanation here is that pytest is trying to load unit test modules, but won't actually run them. -m pylint is a mark filter which means that only tests marked as "pylint" will have to be run. So pytest has to look through all the tests and inspect their marks. I would guess that solving the import/pythonpath issues would address the problem and py.test --pylint -m pylint would behave as expected. – Gediminas Feb 7 at 20:47