summaryrefslogtreecommitdiff
path: root/tasks.py
diff options
context:
space:
mode:
authorJeff Forcier <jeff@bitprophet.org>2017-11-20 13:03:13 -0800
committerJeff Forcier <jeff@bitprophet.org>2018-05-16 16:48:17 -0400
commit033dbdad3dc01444b698c90012e1c43ff99cacb8 (patch)
tree9c42b851fbf56c2474b506dadc210eed0ae60510 /tasks.py
parent6f4fdf0e42cffc61420e695aa8ddf25fb2981a60 (diff)
downloadparamiko-033dbdad3dc01444b698c90012e1c43ff99cacb8.tar.gz
Update custom test task to encompass recent updates to invocations.pytest
No time rn to overhaul Invoke to allow true reuse. bah.
Diffstat (limited to 'tasks.py')
-rw-r--r--tasks.py33
1 files changed, 30 insertions, 3 deletions
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)