mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-17 20:45:44 +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:
@ -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}',
|
||||
|
Reference in New Issue
Block a user