'How to mention file name in nox + pytest?
My nox function looks something like this
@nox.session(python=["3.7", "3.8", "3.9"])
def test(session: nox.Session) -> None:
"""Run unit tests."""
session.install("-e", ".[all]")
session.install("-e", ".[tests]")
print (session.posargs)
session.run("pytest", *session.posargs)
How to update the above function to run tests of specific files or file patterns like tests/*/test_postgres_*.py
Solution 1:[1]
Here’s a quick example that demonstrates how to use arguments to run tests against a particular file:
@nox.session
def test(session):
session.install('pytest')
if session.posargs:
test_files = session.posargs
else:
test_files = ['test_a.py', 'test_b.py']
session.run('pytest', *test_files)
you run:
nox -- test_c.py
Then nox will run:
pytest test_c.py
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | baulin |
