Test flexibility (#4945)

* Add option to specify which tests to run in invoke test

* Add information on testing in CONTRIBUTING.md
This commit is contained in:
miggland 2023-06-01 15:54:06 +02:00 committed by GitHub
parent 4d9e92011e
commit 11c5ce5f80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 4 deletions

View File

@ -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.

View File

@ -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 <module>.<file>.<class>.<method>',
}
)
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:
<module>.<file>.<class>.<method>
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'})