In tox, I can get the site-packages directory of the current environment with the envsitepackagesdir
magic variable. How do I do the same thing in nox
? This is particularly useful when trying to get coverage of my package.
import nox
@nox.session()
def test(session):
session.install('.')
session.install('pytest', 'pytest-cov')
session.run('pytest', '--cov', f'{session.virtualenv.site_packages_dir}/mypackage')
As long as you are actually installing a nox environment (not using
venv_backend='none'
), you can calculate this from the location of the virtual environment andplatform.sys
: