2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-12 10:05:39 +00:00

Unit Test Improvements (#5087)

* Disable migration testing

- Compare how long the unit tests take

* Change file

- To get unit tests to run

* Fix format

* Consolidate tasks.py

- Remove coverage task
- Add --coverage flag to test task

* Fix typo

* Run migration unit tests if migration files are updated

* Fix

* Touch migration file

- Should cause migration unit tests to be run

* Force migration checks for docker build

* Prevent default report creation in unit tests

- Should save some time

* Add simple profiling for plugin loading

- Display time taken to load each plugin

* Fix to invoke test

* Disable get_git_log (for testing)

* Disable get_git_path in CI

- Might remove this entirely?
- For now, bypass for unit testing

* Add debug for unit registry

- Display time taken to load registry

* Don't full-reload unit registry

* Adjust migration test workflow

- env var updates
- change paths-filter output

* Fix for migration_test.yaml

- Actually need to set the output

* env fix

* db name

* Prevent sleep if in test mode

* Reduce sleep time on wait_for_db
This commit is contained in:
Oliver
2023-06-23 17:25:59 +10:00
committed by GitHub
parent 693d24b4b6
commit 3b4e20b54a
14 changed files with 127 additions and 58 deletions

View File

@ -565,9 +565,12 @@ def test_translations(c):
help={
'disable_pty': 'Disable PTY',
'runtest': 'Specify which tests to run, in format <module>.<file>.<class>.<method>',
'migrations': 'Run migration unit tests',
'report': 'Display a report of slow tests',
'coverage': 'Run code coverage analysis (requires coverage package)',
}
)
def test(c, disable_pty=False, runtest=''):
def test(c, disable_pty=False, runtest='', migrations=False, report=False, coverage=False):
"""Run unit-tests for InvenTree codebase.
To run only certain test, use the argument --runtest.
@ -583,8 +586,32 @@ def test(c, disable_pty=False, runtest=''):
pty = not disable_pty
# Run coverage tests
manage(c, f'test --slowreport {runtest}', pty=pty)
_apps = ' '.join(apps())
cmd = 'test'
if runtest:
# Specific tests to run
cmd += f' {runtest}'
else:
# Run all tests
cmd += f' {_apps}'
if report:
cmd += ' --slowreport'
if migrations:
cmd += ' --tag migration_test'
else:
cmd += ' --exclude-tag migration_test'
if coverage:
# Run tests within coverage environment, and generate report
c.run(f'coverage run {managePyPath()} {cmd}')
c.run('coverage html -i')
else:
# Run simple test runner, without coverage
manage(c, cmd, pty=pty)
@task(help={'dev': 'Set up development environment at the end'})
@ -629,25 +656,6 @@ def setup_test(c, ignore_update=False, dev=False, path="inventree-demo-dataset")
setup_dev(c)
@task
def coverage(c):
"""Run code-coverage of the InvenTree codebase, using the 'coverage' code-analysis tools.
Generates a code coverage report (available in the htmlcov directory)
"""
# Run sanity check on the django install
manage(c, 'check')
# Run coverage tests
c.run('coverage run {manage} test {apps}'.format(
manage=managePyPath(),
apps=' '.join(apps())
))
# Generate coverage report
c.run('coverage html -i')
@task(help={
'filename': "Output filename (default = 'schema.yml')",
'overwrite': "Overwrite existing files without asking first (default = off/False)",