mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-17 18:26:32 +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:
4
.github/workflows/docker.yaml
vendored
4
.github/workflows/docker.yaml
vendored
@@ -124,10 +124,10 @@ jobs:
|
|||||||
- name: Run Unit Tests
|
- name: Run Unit Tests
|
||||||
run: |
|
run: |
|
||||||
echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> contrib/container/docker.dev.env
|
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
|
- name: Run Migration Tests
|
||||||
run: |
|
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
|
- name: Clean up test folder
|
||||||
run: |
|
run: |
|
||||||
rm -rf InvenTree/_testfolder
|
rm -rf InvenTree/_testfolder
|
||||||
|
8
.github/workflows/qc_checks.yaml
vendored
8
.github/workflows/qc_checks.yaml
vendored
@@ -341,7 +341,7 @@ jobs:
|
|||||||
- name: Check Migration Files
|
- name: Check Migration Files
|
||||||
run: python3 .github/scripts/check_migration_files.py
|
run: python3 .github/scripts/check_migration_files.py
|
||||||
- name: Coverage Tests
|
- name: Coverage Tests
|
||||||
run: invoke dev.test --coverage --translations
|
run: invoke dev.test --check --coverage --translations
|
||||||
- name: Upload raw coverage to artifacts
|
- name: Upload raw coverage to artifacts
|
||||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # pin@v4.6.2
|
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # pin@v4.6.2
|
||||||
with:
|
with:
|
||||||
@@ -400,7 +400,7 @@ jobs:
|
|||||||
dev-install: true
|
dev-install: true
|
||||||
update: true
|
update: true
|
||||||
- name: Run Tests
|
- name: Run Tests
|
||||||
run: invoke dev.test --translations
|
run: invoke dev.test --check --translations
|
||||||
- name: Data Export Test
|
- name: Data Export Test
|
||||||
uses: ./.github/actions/migration
|
uses: ./.github/actions/migration
|
||||||
|
|
||||||
@@ -448,7 +448,7 @@ jobs:
|
|||||||
dev-install: true
|
dev-install: true
|
||||||
update: true
|
update: true
|
||||||
- name: Run Tests
|
- name: Run Tests
|
||||||
run: invoke dev.test --translations
|
run: invoke dev.test --check --translations
|
||||||
- name: Data Export Test
|
- name: Data Export Test
|
||||||
uses: ./.github/actions/migration
|
uses: ./.github/actions/migration
|
||||||
|
|
||||||
@@ -490,7 +490,7 @@ jobs:
|
|||||||
dev-install: true
|
dev-install: true
|
||||||
update: true
|
update: true
|
||||||
- name: Run Tests
|
- 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
|
- name: Upload coverage reports to Codecov
|
||||||
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # pin@v5.4.3
|
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # pin@v5.4.3
|
||||||
if: always()
|
if: always()
|
||||||
|
@@ -47,6 +47,12 @@ def isRunningBackup():
|
|||||||
|
|
||||||
def isGeneratingSchema():
|
def isGeneratingSchema():
|
||||||
"""Return true if schema generation is being executed."""
|
"""Return true if schema generation is being executed."""
|
||||||
|
if isInServerThread() or isInWorkerThread():
|
||||||
|
return False
|
||||||
|
|
||||||
|
if isInTestMode():
|
||||||
|
return False
|
||||||
|
|
||||||
if 'schema' in sys.argv:
|
if 'schema' in sys.argv:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@@ -814,7 +814,7 @@ inventree_tags = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# sentry.io integration for error reporting
|
# 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
|
'INVENTREE_SENTRY_ENABLED', 'sentry_enabled', False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
20
tasks.py
20
tasks.py
@@ -1212,33 +1212,29 @@ def test_translations(c):
|
|||||||
|
|
||||||
@task(
|
@task(
|
||||||
help={
|
help={
|
||||||
|
'check': 'Run sanity check on the django install (default = False)',
|
||||||
'disable_pty': 'Disable PTY',
|
'disable_pty': 'Disable PTY',
|
||||||
'runtest': 'Specify which tests to run, in format <module>.<file>.<class>.<method>',
|
'runtest': 'Specify which tests to run, in format <module>.<file>.<class>.<method>',
|
||||||
'migrations': 'Run migration unit tests',
|
'migrations': 'Run migration unit tests',
|
||||||
'report': 'Display a report of slow tests',
|
'report': 'Display a report of slow tests',
|
||||||
'coverage': 'Run code coverage analysis (requires coverage package)',
|
'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(
|
def test(
|
||||||
c,
|
c,
|
||||||
|
check=False,
|
||||||
disable_pty=False,
|
disable_pty=False,
|
||||||
runtest='',
|
runtest='',
|
||||||
migrations=False,
|
migrations=False,
|
||||||
report=False,
|
report=False,
|
||||||
coverage=False,
|
coverage=False,
|
||||||
translations=False,
|
translations=False,
|
||||||
|
keepdb=False,
|
||||||
):
|
):
|
||||||
"""Run unit-tests for InvenTree codebase.
|
"""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.
|
To run only certain test, use the argument --runtest.
|
||||||
This can filter all the way down to:
|
This can filter all the way down to:
|
||||||
<module>.<file>.<class>.<method>
|
<module>.<file>.<class>.<method>
|
||||||
@@ -1248,7 +1244,8 @@ def test(
|
|||||||
will run tests in the company/test_api.py file.
|
will run tests in the company/test_api.py file.
|
||||||
"""
|
"""
|
||||||
# Run sanity check on the django install
|
# Run sanity check on the django install
|
||||||
manage(c, 'check')
|
if check:
|
||||||
|
manage(c, 'check')
|
||||||
|
|
||||||
if translations:
|
if translations:
|
||||||
try:
|
try:
|
||||||
@@ -1272,6 +1269,9 @@ def test(
|
|||||||
if report:
|
if report:
|
||||||
cmd += ' --slowreport'
|
cmd += ' --slowreport'
|
||||||
|
|
||||||
|
if keepdb:
|
||||||
|
cmd += ' --keepdb'
|
||||||
|
|
||||||
if migrations:
|
if migrations:
|
||||||
cmd += ' --tag migration_test'
|
cmd += ' --tag migration_test'
|
||||||
else:
|
else:
|
||||||
|
Reference in New Issue
Block a user