mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Slow tests (#4435)
* Add integration for django-slowtest * Sample test improvement - Reduces test from 0.7s to 0.2s * Run CI tests with slowreport * Fix requirements file * Fix test command * Fix bulk_create in unit tests * Remove bulk_create entirely * remove another bulk_create call * Reduce long test from ~1000 seconds to ~1 second
This commit is contained in:
parent
ec66e5351b
commit
db42ffcf7c
@ -32,15 +32,24 @@ INVENTREE_NEWS_URL = 'https://inventree.org/news/feed.atom'
|
||||
# Determine if we are running in "test" mode e.g. "manage.py test"
|
||||
TESTING = 'test' in sys.argv
|
||||
|
||||
# Note: The following fix is "required" for docker build workflow
|
||||
# Note: 2022-12-12 still unsure why...
|
||||
if TESTING and os.getenv('INVENTREE_DOCKER'):
|
||||
# Ensure that sys.path includes global python libs
|
||||
site_packages = '/usr/local/lib/python3.9/site-packages'
|
||||
if TESTING:
|
||||
|
||||
if site_packages not in sys.path:
|
||||
print("Adding missing site-packages path:", site_packages)
|
||||
sys.path.append(site_packages)
|
||||
# Use a weaker password hasher for testing (improves testing speed)
|
||||
PASSWORD_HASHERS = ['django.contrib.auth.hashers.MD5PasswordHasher',]
|
||||
|
||||
# Enable slow-test-runner
|
||||
TEST_RUNNER = 'django_slowtests.testrunner.DiscoverSlowestTestsRunner'
|
||||
NUM_SLOW_TESTS = 25
|
||||
|
||||
# Note: The following fix is "required" for docker build workflow
|
||||
# Note: 2022-12-12 still unsure why...
|
||||
if os.getenv('INVENTREE_DOCKER'):
|
||||
# Ensure that sys.path includes global python libs
|
||||
site_packages = '/usr/local/lib/python3.9/site-packages'
|
||||
|
||||
if site_packages not in sys.path:
|
||||
print("Adding missing site-packages path:", site_packages)
|
||||
sys.path.append(site_packages)
|
||||
|
||||
# Are environment variables manipulated by tests? Needs to be set by testing code
|
||||
TESTING_ENV = False
|
||||
@ -901,7 +910,6 @@ CUSTOM_LOGO = get_custom_file('INVENTREE_CUSTOM_LOGO', 'customize.logo', 'custom
|
||||
CUSTOM_SPLASH = get_custom_file('INVENTREE_CUSTOM_SPLASH', 'customize.splash', 'custom splash')
|
||||
|
||||
CUSTOMIZE = get_setting('INVENTREE_CUSTOMIZE', 'customize', {})
|
||||
|
||||
if DEBUG:
|
||||
logger.info("InvenTree running with DEBUG enabled")
|
||||
|
||||
|
@ -2957,17 +2957,28 @@ class PartStocktakeTest(InvenTreeAPITestCase):
|
||||
|
||||
total = 0
|
||||
|
||||
# Create some entries
|
||||
for p in Part.objects.all():
|
||||
# Iterate over (up to) 5 parts in the database
|
||||
for p in Part.objects.all()[:5]:
|
||||
|
||||
for n in range(p.pk):
|
||||
PartStocktake.objects.create(
|
||||
part=p,
|
||||
quantity=(n + 1) * 100,
|
||||
# Create some entries
|
||||
to_create = []
|
||||
|
||||
n = p.pk % 10
|
||||
|
||||
for idx in range(n):
|
||||
to_create.append(
|
||||
PartStocktake(
|
||||
part=p,
|
||||
quantity=(idx + 1) * 100,
|
||||
)
|
||||
)
|
||||
|
||||
total += p.pk
|
||||
total += 1
|
||||
|
||||
# Create all entries in a single bulk-create
|
||||
PartStocktake.objects.bulk_create(to_create)
|
||||
|
||||
# Query list endpoint
|
||||
response = self.get(
|
||||
url,
|
||||
{
|
||||
@ -2976,8 +2987,8 @@ class PartStocktakeTest(InvenTreeAPITestCase):
|
||||
expected_code=200,
|
||||
)
|
||||
|
||||
# List by part ID
|
||||
self.assertEqual(len(response.data), p.pk)
|
||||
# Check that the expected number of PartStocktake instances has been created
|
||||
self.assertEqual(len(response.data), n)
|
||||
|
||||
# List all entries
|
||||
response = self.get(url, {}, expected_code=200)
|
||||
|
@ -256,8 +256,6 @@ class CategoryTest(TestCase):
|
||||
|
||||
# At this point, we are confident that the tree is correctly structured
|
||||
|
||||
# Add some parts to category B3
|
||||
|
||||
for i in range(10):
|
||||
Part.objects.create(
|
||||
name=f'Part {i}',
|
||||
|
@ -3,6 +3,7 @@
|
||||
coverage # Unit test coverage
|
||||
coveralls==2.1.2 # Coveralls linking (for tracking coverage) # PINNED 2022-06-28 - Old version needed for correct upload
|
||||
django-debug-toolbar # Debug / profiling toolbar
|
||||
django-slowtests # Show which unit tests are running slowly
|
||||
django-test-migrations # Unit testing for database migrations
|
||||
flake8 # PEP checking
|
||||
flake8-docstrings # docstring format testing
|
||||
|
@ -190,10 +190,14 @@ django==3.2.18 \
|
||||
# via
|
||||
# -c requirements.txt
|
||||
# django-debug-toolbar
|
||||
# django-slowtests
|
||||
django-debug-toolbar==3.8.1 \
|
||||
--hash=sha256:24ef1a7d44d25e60d7951e378454c6509bf536dce7e7d9d36e7c387db499bc27 \
|
||||
--hash=sha256:879f8a4672d41621c06a4d322dcffa630fc4df056cada6e417ed01db0e5e0478
|
||||
# via -r requirements-dev.in
|
||||
django-slowtests==1.1.1 \
|
||||
--hash=sha256:3c6936d420c9df444ac03625b41d97de043c662bbde61fbcd33e4cd407d0c247
|
||||
# via -r requirements-dev.in
|
||||
django-test-migrations==1.2.0 \
|
||||
--hash=sha256:874884ff4e980583cd9f1c986bb9fbfe72b436e759be23004e4f52c26a15f363 \
|
||||
--hash=sha256:9e8b9b4364fef70dde10a5f85c5a75d447ca2189ec648325610fab1268daec97
|
||||
|
Loading…
Reference in New Issue
Block a user