witty-laptop-37343
03/07/2023, 11:03 PM./pants test t.py -- --name "Ben" --age 30 --year 2017
?lemon-helicopter-73409
03/07/2023, 11:10 PMpants.toml
file:
[pytest]
lockfile = ".build-support/pytest.lockfile"
args = [
"-ra -q -vv --no-header",
"--reuse-db",
"--no-migrations",
]
lemon-helicopter-73409
03/07/2023, 11:11 PMwitty-laptop-37343
03/07/2023, 11:11 PMlemon-helicopter-73409
03/07/2023, 11:12 PMwitty-laptop-37343
03/07/2023, 11:12 PMwitty-laptop-37343
03/07/2023, 11:12 PMhigh-yak-85899
03/07/2023, 11:14 PMpytest <args>
should work with ./pants test <module> -- <args>
witty-laptop-37343
03/07/2023, 11:19 PMERROR: usage: pex [options] [file_or_dir] [file_or_dir] [...]
pex: error: unrecognized arguments: --name
witty-laptop-37343
03/07/2023, 11:57 PMwitty-crayon-22786
03/07/2023, 11:59 PM./pants test $file -- -k $testname -vvv
…for example.witty-crayon-22786
03/07/2023, 11:59 PMpytest
though. what defines “--age” and “--name”?witty-crayon-22786
03/08/2023, 12:00 AMwitty-crayon-22786
03/08/2023, 12:01 AMenough-analyst-54434
03/08/2023, 12:04 AM$ pants test --output=all src/python/pants/util/strutil_test.py -- -vvs -k test_bullet_list
16:04:00.62 [INFO] Completed: Run Pytest - src/python/pants/util/strutil_test.py:tests - succeeded.
============================= test session starts ==============================
collecting ... collected 18 items / 16 deselected / 2 selected
src/python/pants/util/strutil_test.py::test_bullet_list PASSED
src/python/pants/util/strutil_test.py::test_bullet_list_max_elements PASSED
- generated xml file: /tmp/pants-sandbox-aolMiY/src.python.pants.util.strutil_test.py.tests.xml -
======================= 2 passed, 16 deselected in 0.18s =======================
✓ src/python/pants/util/strutil_test.py:tests succeeded in 0.45s.
enough-analyst-54434
03/08/2023, 12:04 AMenough-analyst-54434
03/08/2023, 12:05 AMwitty-laptop-37343
03/08/2023, 12:35 AMdef pytest_addoption(parser):
parser.addoption('--name', action='store', default=None)
parser.addoption('--age', action='store', default=20)
then I use fixture
@pytest.fixture(scope='session')
def name(pytestconfig):
return pytestconfig.getoption('name')
witty-laptop-37343
03/08/2023, 12:37 AMwitty-laptop-37343
03/08/2023, 12:39 AMenough-analyst-54434
03/08/2023, 12:41 AMpython_test_utils
target owning that file. Do you have that? https://www.pantsbuild.org/docs/reference-python_test_utilswitty-laptop-37343
03/08/2023, 12:42 AM./pants test <test_file_name> -- --arg1 val1 --arg2 val2
work for you?enough-analyst-54434
03/08/2023, 12:42 AMwitty-laptop-37343
03/08/2023, 12:43 AMenough-analyst-54434
03/08/2023, 12:43 AMenough-analyst-54434
03/08/2023, 12:44 AMpants test path/to/file -- --help
enough-analyst-54434
03/08/2023, 12:45 AMwitty-laptop-37343
03/08/2023, 12:46 AMenough-analyst-54434
03/08/2023, 12:46 AMenough-analyst-54434
03/08/2023, 12:47 AMenough-analyst-54434
03/08/2023, 12:47 AMwitty-laptop-37343
03/08/2023, 12:48 AMwitty-laptop-37343
03/08/2023, 12:48 AMwitty-laptop-37343
03/08/2023, 12:52 AM./pants test t.py -- --name "Ben"
or
./pants test t.py -- --age 20
happy-kitchen-89482
03/08/2023, 12:57 AM./pants test t.py -- '--name "Ben" --age 20'
witty-laptop-37343
03/08/2023, 1:30 AMError: file or directory not found: --name "Ben" --age 20
happy-kitchen-89482
03/08/2023, 4:05 AMhappy-kitchen-89482
03/08/2023, 4:06 AM--keep-sandboxes=always
Pants will preserve (and log) the sandbox it used to run pytest in, and __run.sh
in the sandbox will run the command again, so you can play with thatwitty-laptop-37343
03/09/2023, 12:20 AMhappy-kitchen-89482
03/09/2023, 5:24 AM--
is passed through to pytest, so this "correct syntax" is a pytest/pytest plugin thing, not a Pants thing