Skip to content

Instantly share code, notes, and snippets.

@saml
Created February 7, 2019 16:58
Show Gist options
  • Save saml/a417fd27f5b1e015c8b69eb125e6037b to your computer and use it in GitHub Desktop.
Save saml/a417fd27f5b1e015c8b69eb125e6037b to your computer and use it in GitHub Desktop.
nox and posargs where it starts with --
import argparse
import nox
@nox.session(python=['2.7', '3.6'])
def tests(session):
parser = argparse.ArgumentParser()
parser.add_argument('--notest', action='store_true', default=False, help='Install dependencies. But do not run test.')
parser.add_argument('args', nargs=argparse.REMAINDER)
args = parser.parse_args(session.posargs)
if not args.notest:
session.run('pytest', *args.args)
"""
$ nox -r -- --foo
nox > Running session tests-2.7
nox > Re-using existing virtualenv at /tmp/.nox/tests-2-7.
usage: nox [-h] [--notest] ...
nox: error: unrecognized arguments: --foo
$ nox -r -- a --foo
nox > Running session tests-2.7
nox > Re-using existing virtualenv at /tmp/.nox/tests-2-7.
nox > pytest a --foo
...
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment