From 11c5ce5f80dc021d3638d63d3fa0498aa0c7f10a Mon Sep 17 00:00:00 2001 From: miggland Date: Thu, 1 Jun 2023 15:54:06 +0200 Subject: [PATCH] Test flexibility (#4945) * Add option to specify which tests to run in invoke test * Add information on testing in CONTRIBUTING.md --- CONTRIBUTING.md | 12 ++++++++++++ tasks.py | 22 ++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0702815af2..11c4621785 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -123,6 +123,18 @@ The InvenTree code base makes use of [GitHub actions](https://github.com/feature The various github actions can be found in the `./github/workflows` directory +### Run tests locally + +To run test locally, use: +``` +invoke test +``` + +To run only partial tests, for example for a module use: +``` +invoke test --runtest order +``` + ## Code Style Sumbitted Python code is automatically checked against PEP style guidelines. Locally you can run `invoke style` to ensure the style checks will pass, before submitting the PR. diff --git a/tasks.py b/tasks.py index b42afb05ed..e199bbd319 100644 --- a/tasks.py +++ b/tasks.py @@ -561,16 +561,30 @@ def test_translations(c): os.environ['TEST_TRANSLATIONS'] = 'True' -@task -def test(c, disable_pty=False): - """Run unit-tests for InvenTree codebase.""" +@task( + help={ + 'disable_pty': 'Disable PTY', + 'runtest': 'Specify which tests to run, in format ...', + } +) +def test(c, disable_pty=False, runtest=''): + """Run unit-tests for InvenTree codebase. + + To run only certain test, use the argument --runtest. + This can filter all the way down to: + ... + + Example: + test --runtest=company.test_api + will run tests in the company/test_api.py file. + """ # Run sanity check on the django install manage(c, 'check') pty = not disable_pty # Run coverage tests - manage(c, 'test --slowreport', pty=pty) + manage(c, f'test --slowreport {runtest}', pty=pty) @task(help={'dev': 'Set up development environment at the end'})