mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-16 03:55:41 +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:
@ -48,7 +48,7 @@ class InvenTreeConfig(AppConfig):
|
||||
self.collect_notification_methods()
|
||||
|
||||
# Ensure the unit registry is loaded
|
||||
InvenTree.conversion.reload_unit_registry()
|
||||
InvenTree.conversion.get_unit_registry()
|
||||
|
||||
if canAppAccessDatabase() or settings.TESTING_ENV:
|
||||
self.add_user_on_startup()
|
||||
|
@ -1,5 +1,7 @@
|
||||
"""Helper functions for converting between units."""
|
||||
|
||||
import logging
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
@ -8,6 +10,9 @@ import pint
|
||||
_unit_registry = None
|
||||
|
||||
|
||||
logger = logging.getLogger('inventree')
|
||||
|
||||
|
||||
def get_unit_registry():
|
||||
"""Return a custom instance of the Pint UnitRegistry."""
|
||||
|
||||
@ -26,6 +31,9 @@ def reload_unit_registry():
|
||||
This function is called at startup, and whenever the database is updated.
|
||||
"""
|
||||
|
||||
import time
|
||||
t_start = time.time()
|
||||
|
||||
global _unit_registry
|
||||
|
||||
_unit_registry = pint.UnitRegistry()
|
||||
@ -39,6 +47,9 @@ def reload_unit_registry():
|
||||
|
||||
# TODO: Allow for custom units to be defined in the database
|
||||
|
||||
dt = time.time() - t_start
|
||||
logger.debug(f'Loaded unit registry in {dt:.3f}s')
|
||||
|
||||
|
||||
def convert_physical_value(value: str, unit: str = None):
|
||||
"""Validate that the provided value is a valid physical quantity.
|
||||
|
@ -18,7 +18,7 @@ class Command(BaseCommand):
|
||||
|
||||
while not connected:
|
||||
|
||||
time.sleep(5)
|
||||
time.sleep(2)
|
||||
|
||||
try:
|
||||
connection.ensure_connection()
|
||||
|
@ -91,13 +91,15 @@ def check_daily_holdoff(task_name: str, n_days: int = 1) -> bool:
|
||||
"""
|
||||
|
||||
from common.models import InvenTreeSetting
|
||||
from InvenTree.ready import isInTestMode
|
||||
|
||||
if n_days <= 0:
|
||||
logger.info(f"Specified interval for task '{task_name}' < 1 - task will not run")
|
||||
return False
|
||||
|
||||
# Sleep a random number of seconds to prevent worker conflict
|
||||
time.sleep(random.randint(1, 5))
|
||||
if not isInTestMode():
|
||||
time.sleep(random.randint(1, 5))
|
||||
|
||||
attempt_key = f'_{task_name}_ATTEMPT'
|
||||
success_key = f'_{task_name}_SUCCESS'
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Generated by Django 3.2.18 on 2023-04-17 05:54
|
||||
# Generated by Django 3.2.18 on 2023-04-17 05:55
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
@ -35,7 +35,7 @@ class LabelConfig(AppConfig):
|
||||
|
||||
def ready(self):
|
||||
"""This function is called whenever the label app is loaded."""
|
||||
if canAppAccessDatabase():
|
||||
if canAppAccessDatabase(allow_test=False):
|
||||
|
||||
try:
|
||||
self.create_labels() # pragma: no cover
|
||||
|
@ -1,6 +1,5 @@
|
||||
"""Helpers for plugin app."""
|
||||
|
||||
import datetime
|
||||
import inspect
|
||||
import logging
|
||||
import pathlib
|
||||
@ -14,8 +13,6 @@ from django.conf import settings
|
||||
from django.core.exceptions import AppRegistryNotReady
|
||||
from django.db.utils import IntegrityError
|
||||
|
||||
from dulwich.repo import NotGitRepository, Repo
|
||||
|
||||
logger = logging.getLogger('inventree')
|
||||
|
||||
|
||||
@ -112,25 +109,34 @@ def get_entrypoints():
|
||||
def get_git_log(path):
|
||||
"""Get dict with info of the last commit to file named in path."""
|
||||
|
||||
import datetime
|
||||
|
||||
from dulwich.repo import NotGitRepository, Repo
|
||||
|
||||
from InvenTree.ready import isInTestMode
|
||||
|
||||
output = None
|
||||
path = path.replace(str(settings.BASE_DIR.parent), '')[1:]
|
||||
|
||||
try:
|
||||
walker = Repo.discover(path).get_walker(paths=[path.encode()], max_entries=1)
|
||||
# only do this if we are not in test mode
|
||||
if not isInTestMode(): # pragma: no cover
|
||||
|
||||
try:
|
||||
commit = next(iter(walker)).commit
|
||||
except StopIteration:
|
||||
walker = Repo.discover(path).get_walker(paths=[path.encode()], max_entries=1)
|
||||
try:
|
||||
commit = next(iter(walker)).commit
|
||||
except StopIteration:
|
||||
pass
|
||||
else:
|
||||
output = [
|
||||
commit.sha().hexdigest(),
|
||||
commit.author.decode().split('<')[0][:-1],
|
||||
commit.author.decode().split('<')[1][:-1],
|
||||
datetime.datetime.fromtimestamp(commit.author_time, ).isoformat(),
|
||||
commit.message.decode().split('\n')[0],
|
||||
]
|
||||
except NotGitRepository:
|
||||
pass
|
||||
else:
|
||||
output = [
|
||||
commit.sha().hexdigest(),
|
||||
commit.author.decode().split('<')[0][:-1],
|
||||
commit.author.decode().split('<')[1][:-1],
|
||||
datetime.datetime.fromtimestamp(commit.author_time, ).isoformat(),
|
||||
commit.message.decode().split('\n')[0],
|
||||
]
|
||||
except NotGitRepository:
|
||||
pass
|
||||
|
||||
if not output:
|
||||
output = 5 * [''] # pragma: no cover
|
||||
|
@ -9,6 +9,7 @@ import importlib
|
||||
import logging
|
||||
import os
|
||||
import subprocess
|
||||
import time
|
||||
from pathlib import Path
|
||||
from typing import Dict, List, OrderedDict
|
||||
|
||||
@ -439,13 +440,16 @@ class PluginsRegistry:
|
||||
continue # continue -> the plugin is not loaded
|
||||
|
||||
# Initialize package - we can be sure that an admin has activated the plugin
|
||||
logger.info(f'Loading plugin `{plg_name}`')
|
||||
logger.debug(f'Loading plugin `{plg_name}`')
|
||||
|
||||
try:
|
||||
t_start = time.time()
|
||||
plg_i: InvenTreePlugin = plg()
|
||||
logger.debug(f'Loaded plugin `{plg_name}`')
|
||||
dt = time.time() - t_start
|
||||
logger.info(f'Loaded plugin `{plg_name}` in {dt:.3f}s')
|
||||
except Exception as error:
|
||||
handle_error(error, log_name='init') # log error and raise it -> disable plugin
|
||||
logger.warning(f"Plugin `{plg_name}` could not be loaded")
|
||||
|
||||
# Safe extra attributes
|
||||
plg_i.is_package = getattr(plg_i, 'is_package', False)
|
||||
|
@ -10,7 +10,7 @@ from plugin.models import PluginConfig
|
||||
|
||||
|
||||
class PluginDetailAPITest(PluginMixin, InvenTreeAPITestCase):
|
||||
"""Tests the plugin API endpoints."""
|
||||
"""Tests the plugin API endpoints"""
|
||||
|
||||
roles = [
|
||||
'admin.add',
|
||||
|
@ -25,7 +25,7 @@ class ReportConfig(AppConfig):
|
||||
logging.getLogger('weasyprint').setLevel(logging.WARNING)
|
||||
|
||||
# Create entries for default report templates
|
||||
if canAppAccessDatabase(allow_test=True):
|
||||
if canAppAccessDatabase(allow_test=False):
|
||||
self.create_default_test_reports()
|
||||
self.create_default_build_reports()
|
||||
self.create_default_bill_of_materials_reports()
|
||||
|
Reference in New Issue
Block a user