2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-16 17:56:30 +00:00

Unit test fixes (#10019)

* Add --keepdb option for unit test

* Reduce server launch overhead

- isGeneratingSchema was EXPENSIVE
- Running a single unit test reduced from 30s to 3s

* Option to disable check
This commit is contained in:
Oliver
2025-07-15 01:30:58 +10:00
committed by GitHub
parent ea00a50dfd
commit d62ac38cb1
5 changed files with 23 additions and 17 deletions

View File

@@ -124,10 +124,10 @@ jobs:
- name: Run Unit Tests
run: |
echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> contrib/container/docker.dev.env
docker compose --project-directory . -f contrib/container/dev-docker-compose.yml run --rm inventree-dev-server invoke dev.test --disable-pty --translations
docker compose --project-directory . -f contrib/container/dev-docker-compose.yml run --rm inventree-dev-server invoke dev.test --check --disable-pty --translations
- name: Run Migration Tests
run: |
docker compose --project-directory . -f contrib/container/dev-docker-compose.yml run --rm inventree-dev-server invoke dev.test --migrations --translations
docker compose --project-directory . -f contrib/container/dev-docker-compose.yml run --rm inventree-dev-server invoke dev.test --check --migrations --translations
- name: Clean up test folder
run: |
rm -rf InvenTree/_testfolder

View File

@@ -341,7 +341,7 @@ jobs:
- name: Check Migration Files
run: python3 .github/scripts/check_migration_files.py
- name: Coverage Tests
run: invoke dev.test --coverage --translations
run: invoke dev.test --check --coverage --translations
- name: Upload raw coverage to artifacts
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # pin@v4.6.2
with:
@@ -400,7 +400,7 @@ jobs:
dev-install: true
update: true
- name: Run Tests
run: invoke dev.test --translations
run: invoke dev.test --check --translations
- name: Data Export Test
uses: ./.github/actions/migration
@@ -448,7 +448,7 @@ jobs:
dev-install: true
update: true
- name: Run Tests
run: invoke dev.test --translations
run: invoke dev.test --check --translations
- name: Data Export Test
uses: ./.github/actions/migration
@@ -490,7 +490,7 @@ jobs:
dev-install: true
update: true
- name: Run Tests
run: invoke dev.test --migrations --report --coverage --translations
run: invoke dev.test --check --migrations --report --coverage --translations
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # pin@v5.4.3
if: always()

View File

@@ -47,6 +47,12 @@ def isRunningBackup():
def isGeneratingSchema():
"""Return true if schema generation is being executed."""
if isInServerThread() or isInWorkerThread():
return False
if isInTestMode():
return False
if 'schema' in sys.argv:
return True

View File

@@ -814,7 +814,7 @@ inventree_tags = {
}
# sentry.io integration for error reporting
SENTRY_ENABLED = get_boolean_setting(
SENTRY_ENABLED = not TESTING and get_boolean_setting(
'INVENTREE_SENTRY_ENABLED', 'sentry_enabled', False
)

View File

@@ -1212,33 +1212,29 @@ def test_translations(c):
@task(
help={
'check': 'Run sanity check on the django install (default = False)',
'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)',
'translations': 'Compile translations before running tests',
'keepdb': 'Keep the test database after running tests (default = False)',
}
)
def test(
c,
check=False,
disable_pty=False,
runtest='',
migrations=False,
report=False,
coverage=False,
translations=False,
keepdb=False,
):
"""Run unit-tests for InvenTree codebase.
Args:
c: Command line context.
disable_pty (bool): Disable PTY (default = False)
runtest (str): Specify which tests to run, in format <module>.<file>.<class>.<method> (default = '')
migrations (bool): Run migration unit tests (default = False)
report (bool): Display a report of slow tests (default = False)
coverage (bool): Run code coverage analysis (requires coverage package) (default = False)
translations (bool): Compile translations before running tests (default = False)
To run only certain test, use the argument --runtest.
This can filter all the way down to:
<module>.<file>.<class>.<method>
@@ -1248,7 +1244,8 @@ def test(
will run tests in the company/test_api.py file.
"""
# Run sanity check on the django install
manage(c, 'check')
if check:
manage(c, 'check')
if translations:
try:
@@ -1272,6 +1269,9 @@ def test(
if report:
cmd += ' --slowreport'
if keepdb:
cmd += ' --keepdb'
if migrations:
cmd += ' --tag migration_test'
else: