41

I'm trying to write a new test for a project and I'd like to test only that one test in tox. I'm already completely sure that other tests are fine, I don't need them being run every time. The only suggestion I've found doesn't work with

ERROR: InvocationError: could not find executable 
int_ua
  • 1,646
  • 2
  • 18
  • 32

3 Answers3

67

As written by jason meridth:

$ tox -e py35 -- project/tests/test_file.py::TestClassName::test_method

But the fine grain is mentioned by beluga.me in the comments: If you have a tox.ini file you might need to add the {posargs} to pytest in tox.ini:

[tox]
envlist = py35

[testenv]
deps =
    pytest
    pytest-cov
    pytest-pep8
commands =
    pip install -e .
    pytest {posargs}

Run one test with unittest

python3 -m unittest -q test_file.TestClassName
Arminius
  • 2,363
  • 1
  • 18
  • 22
Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
8

Run this command:

tox -epy27 -- test_name

for more information.

Édouard Lopez
  • 40,270
  • 28
  • 126
  • 178
Yael
  • 1,566
  • 3
  • 18
  • 25
  • 1
    I can't make this work for me with either tox 2.6 or 2.7, it will always run all tests even with e.g. `tox -e py27-django18 -- idontexistatall` – djangonaut Apr 07 '17 at 12:52
  • 29
    Found my issue, one should have a close look at the tox.ini, if the `commands =` doesn't have a `{posargs}` it will disregard whatever you add to your command. – djangonaut Apr 07 '17 at 15:54
0

pytest -k <<<test_name>> will work

user9920500
  • 606
  • 7
  • 21