From 033dbdad3dc01444b698c90012e1c43ff99cacb8 Mon Sep 17 00:00:00 2001 From: Jeff Forcier Date: Mon, 20 Nov 2017 13:03:13 -0800 Subject: Update custom test task to encompass recent updates to invocations.pytest No time rn to overhaul Invoke to allow true reuse. bah. --- tasks.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'tasks.py') diff --git a/tasks.py b/tasks.py index 3b34818c..d5ed25b1 100644 --- a/tasks.py +++ b/tasks.py @@ -8,8 +8,21 @@ from invocations.packaging.release import ns as release_coll, publish from invocations.testing import count_errors +# TODO: this screams out for the invoke missing-feature of "I just wrap task X, +# assume its signature by default" (even if that is just **kwargs support) @task -def test(ctx, verbose=True, coverage=False, include_slow=False, opts=""): +def test( + ctx, + verbose=True, + color=True, + capture='sys', + module=None, + k=None, + x=False, + opts="", + coverage=False, + include_slow=False, +): """ Run unit tests via pytest. @@ -20,14 +33,28 @@ def test(ctx, verbose=True, coverage=False, include_slow=False, opts=""): """ if verbose and '--verbose' not in opts and '-v' not in opts: opts += " --verbose" + # TODO: forget why invocations.pytest added this; is it to force color when + # running headless? Probably? + if color: + opts += " --color=yes" + opts += ' --capture={0}'.format(capture) if '-m' not in opts and not include_slow: opts += " -m 'not slow'" + if k is not None and not ('-k' in opts if opts else False): + opts += ' -k {}'.format(k) + if x and not ('-x' in opts if opts else False): + opts += ' -x' + modstr = "" + if module is not None: + # NOTE: implicit test_ prefix as we're not on pytest-relaxed yet + modstr = " tests/test_{}.py".format(module) + # Switch runner depending on coverage or no coverage. + # TODO: get pytest's coverage plugin working, IIRC it has issues? runner = "pytest" if coverage: # Leverage how pytest can be run as 'python -m pytest', and then how # coverage can be told to run things in that manner instead of # expecting a literal .py file. - # TODO: get pytest's coverage plugin working, IIRC it has issues? runner = "coverage run --source=paramiko -m pytest" # Strip SSH_AUTH_SOCK from parent env to avoid pollution by interactive # users. @@ -37,7 +64,7 @@ def test(ctx, verbose=True, coverage=False, include_slow=False, opts=""): env = dict(os.environ) if 'SSH_AUTH_SOCK' in env: del env['SSH_AUTH_SOCK'] - cmd = "{} {}".format(runner, opts) + cmd = "{} {} {}".format(runner, opts, modstr) # NOTE: we have a pytest.ini and tend to use that over PYTEST_ADDOPTS. ctx.run(cmd, pty=True, env=env, replace_env=True) -- cgit v1.2.1