rhythmic-glass-66959
07/18/2022, 6:58 PMdependencies
field in python_test
target), but can we do the same with arguments?happy-kitchen-89482
07/18/2022, 7:17 PMhappy-kitchen-89482
07/18/2022, 7:18 PM./pants test <targets> -- <pytest args"
but not per-testhappy-kitchen-89482
07/18/2022, 7:18 PMhappy-kitchen-89482
07/18/2022, 7:18 PMhundreds-father-404
07/18/2022, 7:31 PMextra_cli_args
to the python_test
target! I think it may be worth doing because it allows you more precision than conftest.py
, which is directory based
rhythmic-glass-66959
07/18/2022, 8:21 PMDJANGO_SETTINGS_MODULE
in pytest.ini (or I guess in pants.toml) or use the --ds
command line flag. The problem is that not all our projects are Django apps. Of course, since I'm new to pants, maybe there's a better way...rhythmic-glass-66959
07/18/2022, 8:26 PMpytest.ini
per-test?hundreds-father-404
07/18/2022, 8:28 PMCan I use a pytest.ini per-test?No. The closest is using
conftest.py
, which inherits Pytest's semantics. It applies for all files in the dir and subdirshundreds-father-404
07/18/2022, 8:28 PMextra_cli_args
field to python_test
, which would give you per-file controlrhythmic-glass-66959
07/18/2022, 8:35 PMdjango_find_project
.rhythmic-glass-66959
07/20/2022, 3:09 PMpytest_load_initial_conftests
since Nautobot does not use DJANGO_SETTINGS_MODULE
to load its configuration. As per the documentation, this hook will not be called for conftest.py
files, only for setuptools plugins. To call a setuptools plugin, you need to use the -p
argument on the command line. So using conftest.py
as suggested won't work in this case and adding a field like extra_cli_args
would be really helpful here. In the meantime, I found a workaround using extra_env_vars
on the python_tests
target like this:
python_tests(
name="tests",
dependencies=[
...,
"src/python/pytest_nautobot",
],
extra_env_vars=[
...,
"PYTEST_ADDOPTS=-p pytest_nautobot"
]
)
Since I'm new to pants, let me know if this make sense or if there's a better way to pass pytest arguments to only a subset of tests.happy-kitchen-89482
07/21/2022, 2:34 AM