From 1a08fe024be9507527854561facf8739e1f6b4b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Stan=C4=9Bk?= Date: Mon, 8 Jul 2024 14:04:01 +0200 Subject: [PATCH] Use importlib mode for pytest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan Staněk --- changelog.d/changed/importlib_mode_pytest.md | 1 + pyproject.toml | 2 +- tests/test_global_licensing.py | 3 ++- tests/test_lint.py | 4 ++-- tests/test_main.py | 3 ++- tests/test_project.py | 3 ++- tests/test_report.py | 4 ++-- tests/test_util.py | 3 ++- 8 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 changelog.d/changed/importlib_mode_pytest.md diff --git a/changelog.d/changed/importlib_mode_pytest.md b/changelog.d/changed/importlib_mode_pytest.md new file mode 100644 index 000000000..45d736ed2 --- /dev/null +++ b/changelog.d/changed/importlib_mode_pytest.md @@ -0,0 +1 @@ +- Tests now use [`--import-mode=importlib`](https://docs.pytest.org/en/stable/explanation/goodpractices.html#which-import-mode). diff --git a/pyproject.toml b/pyproject.toml index 51f587a62..09af3db20 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -139,7 +139,7 @@ use_parentheses = true line_length = 80 [tool.pytest.ini_options] -addopts = "--doctest-modules" +addopts = "--doctest-modules --import-mode=importlib" [tool.mypy] files = [ diff --git a/tests/test_global_licensing.py b/tests/test_global_licensing.py index bd2b289d8..d6a04cbe0 100644 --- a/tests/test_global_licensing.py +++ b/tests/test_global_licensing.py @@ -9,7 +9,6 @@ from pathlib import Path import pytest -from conftest import RESOURCES_DIRECTORY, posix from debian.copyright import Copyright from license_expression import LicenseSymbol @@ -26,6 +25,8 @@ ReuseTOML, ) +from .conftest import RESOURCES_DIRECTORY, posix + # REUSE-IgnoreStart # pylint: disable=redefined-outer-name,too-many-lines diff --git a/tests/test_lint.py b/tests/test_lint.py index 6ca93f9fd..d22d06924 100644 --- a/tests/test_lint.py +++ b/tests/test_lint.py @@ -9,12 +9,12 @@ import re import shutil -from conftest import cpython, posix - from reuse.lint import format_lines, format_plain from reuse.project import Project from reuse.report import ProjectReport +from .conftest import cpython, posix + # REUSE-IgnoreStart diff --git a/tests/test_main.py b/tests/test_main.py index 3068b330f..633084dac 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -24,7 +24,6 @@ from urllib.error import URLError import pytest -from conftest import RESOURCES_DIRECTORY from freezegun import freeze_time from reuse import download @@ -32,6 +31,8 @@ from reuse._util import GIT_EXE, HG_EXE, PIJUL_EXE, cleandoc_nl from reuse.report import LINT_VERSION +from .conftest import RESOURCES_DIRECTORY + # REUSE-IgnoreStart diff --git a/tests/test_project.py b/tests/test_project.py index 0041466ea..c118caa87 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -14,7 +14,6 @@ from pathlib import Path import pytest -from conftest import RESOURCES_DIRECTORY, posix from license_expression import LicenseSymbol from reuse import ReuseInfo, SourceType @@ -26,6 +25,8 @@ ) from reuse.project import GlobalLicensingConflict, Project +from .conftest import RESOURCES_DIRECTORY, posix + # REUSE-IgnoreStart diff --git a/tests/test_report.py b/tests/test_report.py index 084d591e0..7052c3d1e 100644 --- a/tests/test_report.py +++ b/tests/test_report.py @@ -13,12 +13,12 @@ from inspect import cleandoc from textwrap import dedent -from conftest import cpython, posix - from reuse import SourceType from reuse.project import Project from reuse.report import FileReport, ProjectReport +from .conftest import cpython, posix + # REUSE-IgnoreStart diff --git a/tests/test_util.py b/tests/test_util.py index ab00bd213..360b2045e 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -18,11 +18,12 @@ import pytest from boolean.boolean import ParseError -from conftest import no_root, posix from reuse import _util from reuse._util import _LICENSING +from .conftest import no_root, posix + # REUSE-IgnoreStart