nose2
nose2 copied to clipboard
Run individual tests when tests are not installed as part of package
I tend to follow the package structure as detailed here . In short, the tests are outside the scope of package
Foo
|
- pyproject.toml
- unittest.cfg
- tox.ini
- tests
|
- __init__.py
- test_one.py
- others
|
- __init__.py
- test_two.py
- src
|
- mypkg
|
- __init__.py
- one.py
- two.py
The tox.ini file looks like
[tox]
minversion = 3.24
envlist = nose2, flake8
isolated_build = True
[testenv:nose2]
description = Run automated code tests
setenv =
TOXINIDIR = {toxinidir}
passenv =
HOME
SETUPTOOLS_*
commands =
nose2 -c {toxinidir}/unittest.cfg --with-coverage --coverage mypkg --coverage-config {toxinidir}/.coveragerc -s {toxinidir}/tests {posargs}
deps =
nose2[coverage_plugin]
beautifulsoup4
webtest
mysqlclient
[testenv:flake8]
changedir = {toxinidir}
deps =
flake8
flake8-print
commands =
flake8 --config={toxinidir}/tox.ini {posargs}
When I do tox -e nose2
, I can run all the tests
How can I tell nose2 to run only few tests (e.g. only others.test_two
).
I tried
tox -e nose2 .tests.test_one
But it shows an error
File ".tox/nose2/lib/python3.9/site-packages/nose2/util.py", line 165, in try_import_module_from_name
module = __import__(".".join(splitted_name))
ValueError: Empty module name