diff --git a/.vscode/launch.json b/.vscode/launch.json index 72fb91dd..798694fb 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -88,6 +88,21 @@ ], "console": "integratedTerminal", "justMyCode": false - } + }, + { + "name": "Python Debugger: Local Attach", + "type": "debugpy", + "request": "attach", + "connect": { + "host": "localhost", + "port": 5678 + }, + "pathMappings": [ + { + "localRoot": "${workspaceFolder}", + "remoteRoot": "." + } + ] + }, ] } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index fe23276e..515ce2e1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,6 +4,10 @@ "cSpell.enableFiletypes": [ "!python" ], + "python.testing.pytestArgs": [ + "--override-ini", "addopts=", + "app", + ], "python.testing.unittestEnabled": false, "python.testing.pytestEnabled": true, "testing.coverageToolbarEnabled": true, diff --git a/app/access/tests/unit/tenancy_object/test_unit_tenancy_object_model.py b/app/access/tests/unit/tenancy_object/test_unit_tenancy_object_model.py index 4105f7c1..86c062ff 100644 --- a/app/access/tests/unit/tenancy_object/test_unit_tenancy_object_model.py +++ b/app/access/tests/unit/tenancy_object/test_unit_tenancy_object_model.py @@ -2,6 +2,7 @@ import pytest from unittest.mock import patch +from django.apps import apps from django.core.exceptions import ObjectDoesNotExist from django.test import TestCase from django.urls.exceptions import NoReverseMatch @@ -633,7 +634,7 @@ class TenancyObjectTest( @classmethod def setUpTestData(self): - class TestModel(TenancyObject): + class MockTenancyObjectModel(TenancyObject): class Meta: @@ -641,9 +642,23 @@ class TenancyObjectTest( verbose_name = 'Test Model' + self.model = MockTenancyObjectModel - self.model = TestModel - self.item = TestModel() + + self.item = MockTenancyObjectModel() + + + + @classmethod + def tearDownClass(self): + + self.item = None + + del apps.all_models['access']['mocktenancyobjectmodel'] + + self.model = None + + super().tearDownClass() diff --git a/app/api/tests/unit/test_unit_api_fields.py b/app/api/tests/unit/test_unit_api_fields.py index 9855dca3..8600c674 100644 --- a/app/api/tests/unit/test_unit_api_fields.py +++ b/app/api/tests/unit/test_unit_api_fields.py @@ -108,17 +108,17 @@ class APIFieldsTestCases: user = request.cls.view_user ) - yield + yield - with django_db_blocker.unblock(): + with django_db_blocker.unblock(): - team_user.delete() + team_user.delete() - view_team.delete() + view_team.delete() - request.cls.view_user.delete() + request.cls.view_user.delete() - del request.cls.kwargs_create_item + del request.cls.kwargs_create_item @pytest.fixture( scope = 'class') @@ -139,9 +139,9 @@ class APIFieldsTestCases: request.cls.api_data = response.data - yield + yield - del request.cls.url_view_kwargs['pk'] + del request.cls.url_view_kwargs['pk'] diff --git a/app/conftest.py b/app/conftest.py index 51027cd1..f17bc0cc 100644 --- a/app/conftest.py +++ b/app/conftest.py @@ -9,6 +9,14 @@ from access.models.organization import Organization +def pytest_configure(config): + + print("\n--- Pytest Launch Arguments ---") + print(f"Command-line arguments: {config.invocation_params.args}") + print(f"Config file options: {config.getini('addopts')}") + print("\n-------------------------------") + + def pytest_pycollect_makeitem(collector, name, obj): """PyTest Test Creation @@ -81,13 +89,13 @@ def create_model(request, django_db_blocker): **request.cls.kwargs_create_item ) - request.cls.item = item + request.cls.item = item yield item with django_db_blocker.unblock(): - request.cls.item.delete() + item.delete() diff --git a/app/core/tests/unit/mixin/test_unit_history_save.py b/app/core/tests/unit/mixin/test_unit_history_save.py index e91732f2..39f2abd0 100644 --- a/app/core/tests/unit/mixin/test_unit_history_save.py +++ b/app/core/tests/unit/mixin/test_unit_history_save.py @@ -1,3 +1,4 @@ +from django.apps import apps from django.db import models from django.test import TestCase @@ -134,7 +135,7 @@ class SaveHistoryMixinTest( @classmethod def setUpTestData(self): - class MockModel(self.model): + class MockSaveHistoryModel(SaveHistory): class Meta: @@ -142,7 +143,15 @@ class SaveHistoryMixinTest( verbose_name = 'unit test' - self.item = MockModel() + self.item = MockSaveHistoryModel() + + + @classmethod + def tearDownClass(self): + + self.item = None + + del apps.all_models['core']['mocksavehistorymodel'] diff --git a/app/core/tests/unit/ticket_base/test_unit_ticket_base_api_fields.py b/app/core/tests/unit/ticket_base/test_unit_ticket_base_api_fields.py index 67c82736..0739b703 100644 --- a/app/core/tests/unit/ticket_base/test_unit_ticket_base_api_fields.py +++ b/app/core/tests/unit/ticket_base/test_unit_ticket_base_api_fields.py @@ -23,37 +23,36 @@ class APITestCases( @pytest.fixture( scope = 'class') def setup_model(self, request, django_db_blocker, model, - organization_one, ): with django_db_blocker.unblock(): request.cls.entity_user = Entity.objects.create( - organization = organization_one, + organization = request.cls.organization, model_notes = 'asdas' ) project = Project.objects.create( - organization = organization_one, + organization = request.cls.organization, name = 'project' ) parent_ticket = request.cls.model.objects.create( - organization = organization_one, + organization = request.cls.organization, title = 'parent ticket', description = 'bla bla', opened_by = request.cls.view_user, ) project_milestone = ProjectMilestone.objects.create( - organization = organization_one, + organization = request.cls.organization, name = 'project milestone one', project = project ) request.cls.kwargs_create_item.update({ 'category': TicketCategory.objects.create( - organization = organization_one, + organization = request.cls.organization, name = 'a category' ), 'opened_by': request.cls.view_user, @@ -78,12 +77,12 @@ class APITestCases( request.cls.entity_user.delete() + parent_ticket.delete() + project_milestone.delete() project.delete() - parent_ticket.delete() - request.cls.kwargs_create_item['category'].delete() if 'ticket_model' in request.cls.url_view_kwargs: diff --git a/app/project_management/tests/unit/project_milestone/test_project_milestone_permission.py b/app/project_management/tests/unit/project_milestone/test_project_milestone_permission.py index d1df4562..0725ef67 100644 --- a/app/project_management/tests/unit/project_milestone/test_project_milestone_permission.py +++ b/app/project_management/tests/unit/project_milestone/test_project_milestone_permission.py @@ -32,8 +32,6 @@ class ProjectMilestonePermissions(TestCase, ModelPermissions): url_name_delete = '_project_milestone_delete' - url_delete_response = reverse('Project Management:_project_view', kwargs={'pk': 1}) + '?tab=milestones' - @classmethod def setUpTestData(self): """Setup Test @@ -57,6 +55,8 @@ class ProjectMilestonePermissions(TestCase, ModelPermissions): organization = self.organization ) + self.url_delete_response = reverse('Project Management:_project_view', kwargs={'pk': self.project.id}) + '?tab=milestones' + self.item = self.model.objects.create( name = 'test_item_' + self.model._meta.model_name, organization = self.organization, diff --git a/makefile b/makefile index b6b2c2fe..738a667a 100644 --- a/makefile +++ b/makefile @@ -39,14 +39,14 @@ docs: docs-lint lint: markdown-mkdocs-lint test: - pytest -s --cov --cov-branch --cov-report term --cov-report xml:artifacts/coverage_unit_functional.xml --cov-report html:artifacts/coverage/unit_functional/ --junit-xml=artifacts/unit_functional.JUnit.xml app/**/tests/unit app/**/tests/functional + pytest --cov-report xml:artifacts/coverage_unit_functional.xml --cov-report html:artifacts/coverage/unit_functional/ --junit-xml=artifacts/unit_functional.JUnit.xml app/**/tests/unit app/**/tests/functional test-functional: - pytest -s --cov --cov-branch --cov-report term --cov-report xml:artifacts/coverage_functional.xml --cov-report html:artifacts/coverage/functional/ --junit-xml=artifacts/functional.JUnit.xml app/**/tests/functional + pytest --cov-report xml:artifacts/coverage_functional.xml --cov-report html:artifacts/coverage/functional/ --junit-xml=artifacts/functional.JUnit.xml app/**/tests/functional test-unit: - pytest -s --cov --cov-branch --cov-report term --cov-report xml:artifacts/coverage_unit.xml --cov-report html:artifacts/coverage/unit/ --junit-xml=artifacts/unit.JUnit.xml app/**/tests/unit + pytest --cov-report xml:artifacts/coverage_unit.xml --cov-report html:artifacts/coverage/unit/ --junit-xml=artifacts/unit.JUnit.xml app/**/tests/unit diff --git a/pyproject.toml b/pyproject.toml index 75ef8636..fea75548 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,6 @@ disable = [ enable = [ "variables" ] - source-roots = [ "app/" ] @@ -16,11 +15,15 @@ allow-global-unused-variables = true init-import = true + [tool.pytest.ini_options] -addopts = '-s app' +addopts = '--cov --cov-branch --cov-report term --tb=long --verbosity=2 --full-trace --showlocals app' + DJANGO_SETTINGS_MODULE = 'app.settings' + +junit_family = 'xunit2' # -- recommended but optional: # python_files = 'tests.py test_*.py *_tests.py' log_cli = true @@ -32,4 +35,4 @@ log_cli_date_format = '%Y-%m-%d %H:%M:%S' # 'tests/*.py', # # 'tests/functional/**/*.py', # # 'tests/unit/**/*.py', -# ] \ No newline at end of file +# ]