From 797d6551b2a1b2837077e749f69214d1c1a799fb Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Tue, 12 Mar 2024 09:53:15 +0100 Subject: [PATCH] TT#121955 define pytest config * coverage: - omit tests files - define data_file * force django in debug mode * remove warning > gerrit/test_commands.py::refreshTest::test_today_format_ko > /code/gerrit/test_commands.py:101: DeprecationWarning: Please use assertRaisesRegex instead. > with self.assertRaisesRegexp( Change-Id: Ia63ba02a8afa27aecd5d0643d665ed4baaaaa24c --- Makefile | 3 ++- gerrit/test_commands.py | 2 +- pyproject.toml | 12 ++++++++++++ repoapi/test/test_settings.py | 5 +---- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 281c6f8..0196db9 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,8 @@ venv_dev: requirements/dev.txt test: test_templates RESULTS=$(RESULTS) pytest-3 -ra --junitxml=$(RESULTS)/junit.xml \ -o cache_dir=$(CACHE_DIR) \ - --cov=. --cov-report=xml:$(RESULTS)/coverage.xml --pep8 + --cov=. --cov-report=xml:$(RESULTS)/coverage.xml --cov-config=pyproject.toml \ + --pep8 test_pylint: RESULTS=$(RESULTS) pytest-3 --junitxml=$(RESULTS)/junit.xml \ diff --git a/gerrit/test_commands.py b/gerrit/test_commands.py index 9aab2c6..d773382 100644 --- a/gerrit/test_commands.py +++ b/gerrit/test_commands.py @@ -98,7 +98,7 @@ class refreshTest(TestCase): @patch("gerrit.management.commands.gerrit.tasks") def test_today_format_ko(self, tasks): - with self.assertRaisesRegexp( + with self.assertRaisesRegex( CommandError, "invalid fromisoformat value" ): call_command("gerrit", "cleanup", "--today=2023-12-19T12:39:58") diff --git a/pyproject.toml b/pyproject.toml index f4c5929..44177b3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,3 +7,15 @@ exclude = ''' | __pycache__ )/ ''' +[tool.pytest.ini_options] +#FAIL_INVALID_TEMPLATE_VARS = true +django_debug_mode = true +DJANGO_SETTINGS_MODULE = "repoapi.settings.test" +pep8ignore = "*.py W503" +[tool.coverage.run] +data_file = "/results/.coverage" +omit = [ + "*/test/*", + "*/tests/*", + "*/test_*.py", +] \ No newline at end of file diff --git a/repoapi/test/test_settings.py b/repoapi/test/test_settings.py index 7d977ff..558aa07 100644 --- a/repoapi/test/test_settings.py +++ b/repoapi/test/test_settings.py @@ -1,4 +1,4 @@ -# Copyright (C) 2020 The Sipwise Team - http://sipwise.com +# Copyright (C) 2020-2024 The Sipwise Team - http://sipwise.com # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free @@ -12,8 +12,6 @@ # # You should have received a copy of the GNU General Public License along # with this program. If not, see . -import unittest - from django.test import override_settings from django.test import SimpleTestCase @@ -24,7 +22,6 @@ class SettingsTest(SimpleTestCase): self.assertTrue(DEBUG) - @unittest.expectedFailure def test_debug(self): from django.conf import settings