David Parks
David Parks

Reputation: 32051

Skipping import modules in pytest from the command line

The documentation for pytest suggests you can skip certain imports:

https://docs.pytest.org/en/latest/skipping.html#skipping-on-a-missing-import-dependency

We are trying to run pylint under pytest and in some cases importing tensorflow causes issues because of system dependencies. The documentation shows a way of skipping the import in code, is it possible to skip imports like this from the command line of pytest?

Upvotes: 1

Views: 930

Answers (1)

wim
wim

Reputation: 362478

There is no such feature in pytest, so you should do this directly in code (usually in a conftest.py).

A hacky workaround to do the same directly at the command line woud be:

python -c "import pytest; pytest.importorskip('tensorflow'); pytest.main()"

Better would be to use one of the existing hooks to add your own command-line option to pytest, so it can be specified clearly like --no-tensorflow or whatever.

Upvotes: 1

Related Questions