From dad167f073bab9791def855ac3ad4c18a37f85db Mon Sep 17 00:00:00 2001 From: longze chen Date: Mon, 13 Aug 2018 15:12:15 -0400 Subject: [PATCH] Improve the command `invoke test` - Add an option `--extension=` to test a specific extension only - Add an option `--path=` to test a specific file or folder only - Add an option `--nocov=` to disable coverage --- tasks.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/tasks.py b/tasks.py index c8c18a854..c5267598a 100644 --- a/tasks.py +++ b/tasks.py @@ -49,11 +49,27 @@ def flake(ctx): @task -def test(ctx, verbose=False): +def test(ctx, verbose=False, nocov=False, extension=None, path=None): + """Run full or customized tests for MFR. + :param ctx: the ``invoke`` context + :param verbose: the flag to increase verbosity + :param nocov: the flag to disable coverage + :param extension: limit the tests to the given extension only + :param path: limit the tests to the given path only + :return: None + """ flake(ctx) - cmd = 'py.test --cov-report term-missing --cov mfr tests' - if verbose: - cmd += ' -v' + # `--extension=` and `--path=` are mutually exclusive options + assert not (extension and path) + if path: + path = '/{}'.format(path) if path else '' + elif extension: + path = '/extensions/{}/'.format(extension) if extension else '' + else: + path = '' + coverage = ' --cov-report term-missing --cov mfr' if not nocov else '' + verbose = '-v' if verbose else '' + cmd = 'py.test{} tests{} {}'.format(coverage, path, verbose) ctx.run(cmd, pty=True)