Py.Test Can't find pytest-parallel when invoked programmatically

426 views Asked by At

I am trying to send parallel arguments by a programmatic invocation to pytest but doesn't seem to recognize them like when parallel is not installed at all, except that I know is there because when I run py.test with a direct command line invocation including the same arguments, it will find it and run successfully.

ERROR: usage: invoke_pytest.py [options] [file_or_dir] [file_or_dir] [...] invoke_pytest.py: error: unrecognized arguments: --workers 1 --tests-per-worker 4

This is my code:

import os
import sys
import pytest


pytest_args = [
    "tests/bdd",
    '--rootdir=tests/bdd',
    "--workers 1",
    "--tests-per-worker 4"
    # ...
]
result = pytest.main(pytest_args)
print(f"RESULT {result}")

Although it seems unrelated, I am also using py.test bdd and splinter for this test suite.

1

There are 1 answers

0
gerosalesc On

Figure out it is the way py.test parse arguments programmatically and has nothing to do with parallel. The values of each argument need to be an independent position of the list!

# ...
pytest_args = [
    "tests/bdd",
    '--rootdir=tests/bdd',
    "--workers", "1",
    "--tests-per-worker", "4", # splitted argument and value
    # ...
]
result = pytest.main(pytest_args)
print(f"RESULT {result}")