From cb00878acd2f7799709484fcba5228f7cc8000bb Mon Sep 17 00:00:00 2001 From: Ariel Schulz Date: Wed, 25 Nov 2026 10:04:30 +0100 Subject: [PATCH 01/18] Removed unnecessary method --- exasol/toolbox/nox/_shared.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/exasol/toolbox/nox/_shared.py b/exasol/toolbox/nox/_shared.py index c897e990d..1b08620aa 100644 --- a/exasol/toolbox/nox/_shared.py +++ b/exasol/toolbox/nox/_shared.py @@ -55,13 +55,6 @@ def validate_path_within_root(path: Path) -> Path: return resolved_path -def _context_parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser( - formatter_class=argparse.ArgumentDefaultsHelpFormatter - ) - return parser - - def _context( session: Session, parser: argparse.ArgumentParser, @@ -76,7 +69,9 @@ def _context( def _unit_test_context(session: Session, **kwargs: Any) -> MutableMapping[str, Any]: - parser = _context_parser() + parser = argparse.ArgumentParser( + formatter_class=argparse.ArgumentDefaultsHelpFormatter + ) parser.add_argument( "--coverage", action="store_true", help="Enable the collection of coverage data" ) @@ -87,7 +82,9 @@ def _integration_test_context( session: Session, **kwargs: Any, ) -> MutableMapping[str, Any]: - parser = _context_parser() + parser = argparse.ArgumentParser( + formatter_class=argparse.ArgumentDefaultsHelpFormatter + ) parser.add_argument( "--coverage", action="store_true", help="Enable the collection of coverage data" ) From 6ed1105967d1c7f9e60af37e1217ce0ed6f58c4f Mon Sep 17 00:00:00 2001 From: Ariel Schulz Date: Wed, 25 Nov 2026 10:46:09 +0100 Subject: [PATCH 02/18] Modify Nox session test:* to allow path specification --- exasol/toolbox/nox/_shared.py | 44 +++++++++--------------------- exasol/toolbox/nox/_test.py | 51 ++++++++++++++++++++--------------- 2 files changed, 42 insertions(+), 53 deletions(-) diff --git a/exasol/toolbox/nox/_shared.py b/exasol/toolbox/nox/_shared.py index 1b08620aa..5ae4435b7 100644 --- a/exasol/toolbox/nox/_shared.py +++ b/exasol/toolbox/nox/_shared.py @@ -1,16 +1,12 @@ from __future__ import annotations import argparse -from collections import ChainMap -from collections.abc import ( - MutableMapping, -) +from dataclasses import dataclass from enum import ( Enum, auto, ) from pathlib import Path -from typing import Any from nox import Session @@ -55,36 +51,30 @@ def validate_path_within_root(path: Path) -> Path: return resolved_path -def _context( - session: Session, - parser: argparse.ArgumentParser, - default_context: dict[str, Any], - **kwargs: Any, -) -> MutableMapping[str, Any]: - namespace, args = parser.parse_known_args(session.posargs) - cli_context: MutableMapping[str, Any] = vars(namespace) - cli_context["fwd-args"] = args - # Note: ChainMap scans last to first - return ChainMap(kwargs, cli_context, default_context) +@dataclass +class ArgparseResults: + known: argparse.Namespace + other: list[str] -def _unit_test_context(session: Session, **kwargs: Any) -> MutableMapping[str, Any]: +def _unit_test_context(session: Session) -> ArgparseResults: parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter ) + default_path = PROJECT_CONFIG.root_path / "test" / "unit" + parser.add_argument("directories", nargs="*", type=Path, default=[default_path]) parser.add_argument( "--coverage", action="store_true", help="Enable the collection of coverage data" ) - return _context(session, parser, {"coverage": False}, **kwargs) + return ArgparseResults(*parser.parse_known_args(session.posargs)) -def _integration_test_context( - session: Session, - **kwargs: Any, -) -> MutableMapping[str, Any]: +def _integration_test_context(session: Session) -> ArgparseResults: parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter ) + default_path = PROJECT_CONFIG.root_path / "test" / "integration" + parser.add_argument("directories", nargs="*", type=Path, default=[default_path]) parser.add_argument( "--coverage", action="store_true", help="Enable the collection of coverage data" ) @@ -93,12 +83,4 @@ def _integration_test_context( default=PROJECT_CONFIG.minimum_exasol_version, help="Specify the Exasol DB version to be used", ) - return _context( - session, - parser, - { - "coverage": False, - "db_version": PROJECT_CONFIG.minimum_exasol_version, - }, - **kwargs, - ) + return ArgparseResults(*parser.parse_known_args(session.posargs)) diff --git a/exasol/toolbox/nox/_test.py b/exasol/toolbox/nox/_test.py index db6f9c4f8..7ec7f37cf 100644 --- a/exasol/toolbox/nox/_test.py +++ b/exasol/toolbox/nox/_test.py @@ -2,16 +2,14 @@ from collections.abc import ( Iterable, - MutableMapping, ) -from pathlib import Path -from typing import Any import nox from nox import Session from exasol.toolbox.config import BaseConfig from exasol.toolbox.nox._shared import ( + ArgparseResults, _integration_test_context, _unit_test_context, ) @@ -22,7 +20,7 @@ def _test_command( - path: Path, config: BaseConfig, context: MutableMapping[str, Any] + config: BaseConfig, argparse_results: ArgparseResults ) -> Iterable[str]: coverage_command = ( [ @@ -32,55 +30,63 @@ def _test_command( f"--rcfile={config.root_path / 'pyproject.toml'}", "-m", ] - if context["coverage"] + if argparse_results.known.coverage else [] ) - pytest_command = ["pytest", "-v", f"{path}"] - return coverage_command + pytest_command + context["fwd-args"] + print(argparse_results.known.directories) + return ( + coverage_command + + ["pytest", *argparse_results.known.directories] + + argparse_results.other + ) def _unit_tests( - session: Session, config: BaseConfig, context: MutableMapping[str, Any] + session: Session, config: BaseConfig, argeparse_results: ArgparseResults ) -> None: - command = _test_command(config.root_path / "test" / "unit", config, context) + command = _test_command(config, argeparse_results) session.run(*command) def _integration_tests( - session: Session, config: BaseConfig, context: MutableMapping[str, Any] + session: Session, config: BaseConfig, argparse_results: ArgparseResults ) -> None: pm = NoxTasks.plugin_manager(config) # run pre integration test plugins - pm.hook.pre_integration_tests_hook(session=session, config=config, context=context) + pm.hook.pre_integration_tests_hook( + session=session, config=config, context=argparse_results + ) # Notes: # - Catch exceptions and ensure post-hooks run before exiting # - Consider making the executed command(s) configurable via a plugin hook # (The default implementation of the hook could provide the current implementation) - command = _test_command(config.root_path / "test" / "integration", config, context) + command = _test_command(config, argparse_results) session.run(*command) # run post integration test plugins - pm.hook.post_integration_tests_hook(session=session, config=config, context=context) + pm.hook.post_integration_tests_hook( + session=session, config=config, context=argparse_results + ) def _coverage( - session: Session, config: BaseConfig, context: MutableMapping[str, Any] + session: Session, config: BaseConfig, argeparse_result: ArgparseResults ) -> None: command = ["coverage", "report", "-m"] coverage_file = config.root_path / ".coverage" coverage_file.unlink(missing_ok=True) - _unit_tests(session, config, context) - _integration_tests(session, config, context) + _unit_tests(session, config, argeparse_result) + _integration_tests(session, config, argeparse_result) session.run(*command) @nox.session(name="test:unit", python=False) def unit_tests(session: Session) -> None: """Runs all unit tests""" - context = _unit_test_context(session) - _unit_tests(session, PROJECT_CONFIG, context) + argeparse_result = _unit_test_context(session) + _unit_tests(session, PROJECT_CONFIG, argeparse_result) @nox.session(name="test:integration", python=False) @@ -93,12 +99,13 @@ def integration_tests(session: Session) -> None: * pre_integration_tests_hook(session: Session, config: Config, context: MutableMapping[str, Any]) -> bool: * post_integration_tests_hook(session: Session, config: Config, context: MutableMapping[str, Any]) -> bool: """ - context = _integration_test_context(session) - _integration_tests(session, PROJECT_CONFIG, context) + argeparse_result = _integration_test_context(session) + _integration_tests(session, PROJECT_CONFIG, argeparse_result) @nox.session(name="test:coverage", python=False) def coverage(session: Session) -> None: """Runs all tests (unit + integration) and reports the code coverage""" - context = _integration_test_context(session, coverage=True) - _coverage(session, PROJECT_CONFIG, context) + argeparse_result = _integration_test_context(session) + argeparse_result.known.coverage = True + _coverage(session, PROJECT_CONFIG, argeparse_result) From acbb2fd1e7d932b3f2202bac1cedb9965c00c35d Mon Sep 17 00:00:00 2001 From: Ariel Schulz Date: Wed, 25 Nov 2026 11:02:20 +0100 Subject: [PATCH 03/18] Remove unused project:check and test:coverage (as not properly implemented) --- exasol/toolbox/nox/_test.py | 19 ------------------- exasol/toolbox/nox/tasks.py | 14 +------------- test/unit/nox/_test_test.py | 19 ------------------- 3 files changed, 1 insertion(+), 51 deletions(-) diff --git a/exasol/toolbox/nox/_test.py b/exasol/toolbox/nox/_test.py index 7ec7f37cf..600dd0944 100644 --- a/exasol/toolbox/nox/_test.py +++ b/exasol/toolbox/nox/_test.py @@ -71,17 +71,6 @@ def _integration_tests( ) -def _coverage( - session: Session, config: BaseConfig, argeparse_result: ArgparseResults -) -> None: - command = ["coverage", "report", "-m"] - coverage_file = config.root_path / ".coverage" - coverage_file.unlink(missing_ok=True) - _unit_tests(session, config, argeparse_result) - _integration_tests(session, config, argeparse_result) - session.run(*command) - - @nox.session(name="test:unit", python=False) def unit_tests(session: Session) -> None: """Runs all unit tests""" @@ -101,11 +90,3 @@ def integration_tests(session: Session) -> None: """ argeparse_result = _integration_test_context(session) _integration_tests(session, PROJECT_CONFIG, argeparse_result) - - -@nox.session(name="test:coverage", python=False) -def coverage(session: Session) -> None: - """Runs all tests (unit + integration) and reports the code coverage""" - argeparse_result = _integration_test_context(session) - argeparse_result.known.coverage = True - _coverage(session, PROJECT_CONFIG, argeparse_result) diff --git a/exasol/toolbox/nox/tasks.py b/exasol/toolbox/nox/tasks.py index c298f85fd..431fbd22f 100644 --- a/exasol/toolbox/nox/tasks.py +++ b/exasol/toolbox/nox/tasks.py @@ -3,9 +3,7 @@ __all__ = [ "Mode", "build_docs", - "check", "clean_docs", - "coverage", "fix_format", "integration_tests", "lint", @@ -32,19 +30,9 @@ from noxconfig import PROJECT_CONFIG -@nox.session(name="project:check", python=False) -def check(session: Session) -> None: - """Runs all available checks on the project""" - context = _integration_test_context(session, coverage=True) - py_files = get_filtered_python_files(PROJECT_CONFIG.root_path) - _code_format(session, Mode.Check, py_files) - _pylint(session, py_files) - _type_check(session, py_files) - _coverage(session, PROJECT_CONFIG, context) + from exasol.toolbox.nox._test import ( - _coverage, - coverage, integration_tests, unit_tests, ) diff --git a/test/unit/nox/_test_test.py b/test/unit/nox/_test_test.py index c44a347cd..c1b36ad14 100644 --- a/test/unit/nox/_test_test.py +++ b/test/unit/nox/_test_test.py @@ -5,7 +5,6 @@ from exasol.toolbox.nox._test import ( _test_command, - coverage, integration_tests, unit_tests, ) @@ -118,21 +117,3 @@ def test_works_without_hooks(nox_session, test_project_config_factory): integration_context.assert_called_once_with(nox_session) assert (test_directory / "__pycache__").exists() - - -def test_coverage_uses_integration_test_context(nox_session): - with ( - patch( - "exasol.toolbox.nox._test._integration_test_context", - return_value={"coverage": True, "db_version": "8.29.13", "fwd-args": []}, - ) as integration_context, - patch("exasol.toolbox.nox._test._coverage") as coverage_impl, - ): - coverage(nox_session) - - integration_context.assert_called_once_with(nox_session, coverage=True) - coverage_impl.assert_called_once_with( - nox_session, - PROJECT_CONFIG, - {"coverage": True, "db_version": "8.29.13", "fwd-args": []}, - ) From 66d0cc5aa4821b28ed6fe528b580939fb027b4d0 Mon Sep 17 00:00:00 2001 From: Ariel Schulz Date: Wed, 25 Nov 2026 11:11:53 +0100 Subject: [PATCH 04/18] Reduce tests to necessary ones --- test/unit/nox/_shared_test.py | 48 ++++------------------------------- 1 file changed, 5 insertions(+), 43 deletions(-) diff --git a/test/unit/nox/_shared_test.py b/test/unit/nox/_shared_test.py index fe1c17faa..bb90f7870 100644 --- a/test/unit/nox/_shared_test.py +++ b/test/unit/nox/_shared_test.py @@ -5,7 +5,6 @@ from exasol.toolbox.nox._shared import ( _integration_test_context, - _unit_test_context, get_filtered_python_files, validate_path_within_root, ) @@ -32,7 +31,7 @@ def directories(test_project_config_factory, package_directory, excluded_python_ additional = { config.root_path / d for d in (package_directory, excluded_python_path) } - yield set(config.excluded_python_paths).union(additional) + return set(config.excluded_python_paths).union(additional) @pytest.fixture @@ -79,53 +78,16 @@ def test_get_filtered_python_files( assert "toolbox/sample.py" in exceptions[0] -def test_unit_test_context_help_excludes_db_version(nox_session): - captured: dict[str, str] = {} - - def _capture_context(session, parser, default_context, **kwargs): - captured["help_text"] = parser.format_help() - return default_context - - with patch("exasol.toolbox.nox._shared._context", side_effect=_capture_context): - _unit_test_context(nox_session) - - help_text = captured["help_text"] - assert "--coverage" in help_text - assert "--db-version" not in help_text - - -def test_integration_test_context_help_includes_db_version(nox_session): - captured: dict[str, str] = {} - - def _capture_context(session, parser, default_context, **kwargs): - captured["help_text"] = parser.format_help() - return default_context - - with patch("exasol.toolbox.nox._shared._context", side_effect=_capture_context): - _integration_test_context(nox_session) - - help_text = captured["help_text"] - assert "--coverage" in help_text - assert "--db-version" in help_text - - -def test_unit_test_context_has_no_db_version(nox_session): - context = _unit_test_context(nox_session) - - assert context["coverage"] is False - assert "db_version" not in context - - -def test_integration_test_context_uses_minimum_exasol_version( +def test_defaul_integration_test_argparse_result( nox_session, test_project_config_factory ): config = test_project_config_factory(exasol_versions=("2025.1.8", "8.29.13")) with patch("exasol.toolbox.nox._shared.PROJECT_CONFIG", config): - context = _integration_test_context(nox_session) + argeparse_result = _integration_test_context(nox_session) - assert context["coverage"] is False - assert context["db_version"] == "8.29.13" + assert argeparse_result.known.coverage is False + assert argeparse_result.known.db_version == "8.29.13" class TestValidatePathWithinRoot: From cb855fee4684d4eaa23be55d5ff189ad57349d8a Mon Sep 17 00:00:00 2001 From: Ariel Schulz Date: Wed, 25 Nov 2026 11:19:40 +0100 Subject: [PATCH 05/18] Move functions out of _shared --- exasol/toolbox/nox/_shared.py | 39 ----------------------------- exasol/toolbox/nox/_test.py | 47 ++++++++++++++++++++++++++++------- exasol/toolbox/nox/tasks.py | 1 - 3 files changed, 38 insertions(+), 49 deletions(-) diff --git a/exasol/toolbox/nox/_shared.py b/exasol/toolbox/nox/_shared.py index 5ae4435b7..7a49cb689 100644 --- a/exasol/toolbox/nox/_shared.py +++ b/exasol/toolbox/nox/_shared.py @@ -1,15 +1,11 @@ from __future__ import annotations -import argparse -from dataclasses import dataclass from enum import ( Enum, auto, ) from pathlib import Path -from nox import Session - from noxconfig import ( PROJECT_CONFIG, ) @@ -49,38 +45,3 @@ def validate_path_within_root(path: Path) -> Path: ) return resolved_path - - -@dataclass -class ArgparseResults: - known: argparse.Namespace - other: list[str] - - -def _unit_test_context(session: Session) -> ArgparseResults: - parser = argparse.ArgumentParser( - formatter_class=argparse.ArgumentDefaultsHelpFormatter - ) - default_path = PROJECT_CONFIG.root_path / "test" / "unit" - parser.add_argument("directories", nargs="*", type=Path, default=[default_path]) - parser.add_argument( - "--coverage", action="store_true", help="Enable the collection of coverage data" - ) - return ArgparseResults(*parser.parse_known_args(session.posargs)) - - -def _integration_test_context(session: Session) -> ArgparseResults: - parser = argparse.ArgumentParser( - formatter_class=argparse.ArgumentDefaultsHelpFormatter - ) - default_path = PROJECT_CONFIG.root_path / "test" / "integration" - parser.add_argument("directories", nargs="*", type=Path, default=[default_path]) - parser.add_argument( - "--coverage", action="store_true", help="Enable the collection of coverage data" - ) - parser.add_argument( - "--db-version", - default=PROJECT_CONFIG.minimum_exasol_version, - help="Specify the Exasol DB version to be used", - ) - return ArgparseResults(*parser.parse_known_args(session.posargs)) diff --git a/exasol/toolbox/nox/_test.py b/exasol/toolbox/nox/_test.py index 600dd0944..8ad11717d 100644 --- a/exasol/toolbox/nox/_test.py +++ b/exasol/toolbox/nox/_test.py @@ -1,22 +1,52 @@ from __future__ import annotations +import argparse from collections.abc import ( Iterable, ) +from dataclasses import dataclass import nox from nox import Session from exasol.toolbox.config import BaseConfig -from exasol.toolbox.nox._shared import ( - ArgparseResults, - _integration_test_context, - _unit_test_context, -) from exasol.toolbox.nox.plugin import NoxTasks -from noxconfig import ( - PROJECT_CONFIG, -) +from noxconfig import PROJECT_CONFIG + + +@dataclass +class ArgparseResults: + known: argparse.Namespace + other: list[str] + + +def _unit_test_context(session: Session) -> ArgparseResults: + parser = argparse.ArgumentParser( + formatter_class=argparse.ArgumentDefaultsHelpFormatter + ) + default_path = PROJECT_CONFIG.root_path / "test" / "unit" + parser.add_argument("directories", nargs="*", type=Path, default=[default_path]) + parser.add_argument( + "--coverage", action="store_true", help="Enable the collection of coverage data" + ) + return ArgparseResults(*parser.parse_known_args(session.posargs)) + + +def _integration_test_context(session: Session) -> ArgparseResults: + parser = argparse.ArgumentParser( + formatter_class=argparse.ArgumentDefaultsHelpFormatter + ) + default_path = PROJECT_CONFIG.root_path / "test" / "integration" + parser.add_argument("directories", nargs="*", type=Path, default=[default_path]) + parser.add_argument( + "--coverage", action="store_true", help="Enable the collection of coverage data" + ) + parser.add_argument( + "--db-version", + default=PROJECT_CONFIG.minimum_exasol_version, + help="Specify the Exasol DB version to be used", + ) + return ArgparseResults(*parser.parse_known_args(session.posargs)) def _test_command( @@ -33,7 +63,6 @@ def _test_command( if argparse_results.known.coverage else [] ) - print(argparse_results.known.directories) return ( coverage_command + ["pytest", *argparse_results.known.directories] diff --git a/exasol/toolbox/nox/tasks.py b/exasol/toolbox/nox/tasks.py index 431fbd22f..886c70e91 100644 --- a/exasol/toolbox/nox/tasks.py +++ b/exasol/toolbox/nox/tasks.py @@ -52,7 +52,6 @@ from exasol.toolbox.nox._skills import check_skills, install_skills from exasol.toolbox.nox._shared import ( Mode, - _integration_test_context, get_filtered_python_files, ) From 7b96009051f063fe5ba1befa90d9ec72b06d8549 Mon Sep 17 00:00:00 2001 From: Ariel Schulz Date: Wed, 25 Nov 2026 11:21:17 +0100 Subject: [PATCH 06/18] Move tests to new location and redistribute per function tested --- test/unit/nox/_shared_test.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/test/unit/nox/_shared_test.py b/test/unit/nox/_shared_test.py index bb90f7870..eeccaf5dc 100644 --- a/test/unit/nox/_shared_test.py +++ b/test/unit/nox/_shared_test.py @@ -4,7 +4,6 @@ import pytest from exasol.toolbox.nox._shared import ( - _integration_test_context, get_filtered_python_files, validate_path_within_root, ) @@ -78,18 +77,6 @@ def test_get_filtered_python_files( assert "toolbox/sample.py" in exceptions[0] -def test_defaul_integration_test_argparse_result( - nox_session, test_project_config_factory -): - config = test_project_config_factory(exasol_versions=("2025.1.8", "8.29.13")) - - with patch("exasol.toolbox.nox._shared.PROJECT_CONFIG", config): - argeparse_result = _integration_test_context(nox_session) - - assert argeparse_result.known.coverage is False - assert argeparse_result.known.db_version == "8.29.13" - - class TestValidatePathWithinRoot: @staticmethod @pytest.mark.parametrize( From e518f4b01957f264ec77971c7e28a5f28b0bbfb6 Mon Sep 17 00:00:00 2001 From: Ariel Schulz Date: Wed, 25 Nov 2026 11:23:19 +0100 Subject: [PATCH 07/18] Consolidate unit_test into nox session --- exasol/toolbox/nox/_test.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/exasol/toolbox/nox/_test.py b/exasol/toolbox/nox/_test.py index 8ad11717d..3ea3a1a5d 100644 --- a/exasol/toolbox/nox/_test.py +++ b/exasol/toolbox/nox/_test.py @@ -70,13 +70,6 @@ def _test_command( ) -def _unit_tests( - session: Session, config: BaseConfig, argeparse_results: ArgparseResults -) -> None: - command = _test_command(config, argeparse_results) - session.run(*command) - - def _integration_tests( session: Session, config: BaseConfig, argparse_results: ArgparseResults ) -> None: @@ -103,8 +96,9 @@ def _integration_tests( @nox.session(name="test:unit", python=False) def unit_tests(session: Session) -> None: """Runs all unit tests""" - argeparse_result = _unit_test_context(session) - _unit_tests(session, PROJECT_CONFIG, argeparse_result) + argparse_results = _unit_test_context(session) + command = _test_command(PROJECT_CONFIG, argparse_results) + session.run(*command) @nox.session(name="test:integration", python=False) From 73a1ad375c6c44b17ded77c1b3d0cc9e98a39d48 Mon Sep 17 00:00:00 2001 From: Ariel Schulz Date: Wed, 25 Nov 2026 11:24:49 +0100 Subject: [PATCH 08/18] Fix with imports --- exasol/toolbox/nox/_test.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/exasol/toolbox/nox/_test.py b/exasol/toolbox/nox/_test.py index 3ea3a1a5d..fbb42f2f8 100644 --- a/exasol/toolbox/nox/_test.py +++ b/exasol/toolbox/nox/_test.py @@ -5,6 +5,7 @@ Iterable, ) from dataclasses import dataclass +from pathlib import Path import nox from nox import Session @@ -108,8 +109,8 @@ def integration_tests(session: Session) -> None: If a project needs to execute code pre-/post the test execution, it should provide appropriate hooks on their config object. - * pre_integration_tests_hook(session: Session, config: Config, context: MutableMapping[str, Any]) -> bool: - * post_integration_tests_hook(session: Session, config: Config, context: MutableMapping[str, Any]) -> bool: + * pre_integration_tests_hook + * post_integration_tests_hook """ - argeparse_result = _integration_test_context(session) - _integration_tests(session, PROJECT_CONFIG, argeparse_result) + argparse_results = _integration_test_context(session) + _integration_tests(session, PROJECT_CONFIG, argparse_results) From 2173df72add85f029feaa8edd1aad028e07c8250 Mon Sep 17 00:00:00 2001 From: Ariel Schulz Date: Wed, 25 Nov 2026 12:37:30 +0100 Subject: [PATCH 09/18] Switch from positional to keyword and clarify a path is allowed (could be directory or file) --- exasol/toolbox/nox/_test.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/exasol/toolbox/nox/_test.py b/exasol/toolbox/nox/_test.py index fbb42f2f8..01d46c9a0 100644 --- a/exasol/toolbox/nox/_test.py +++ b/exasol/toolbox/nox/_test.py @@ -14,6 +14,9 @@ from exasol.toolbox.nox.plugin import NoxTasks from noxconfig import PROJECT_CONFIG +UNIT_TESTS_DIRECTORY = PROJECT_CONFIG.root_path / "test" / "unit" +INTEGRATION_TESTS_DIRECTORY = PROJECT_CONFIG.root_path / "test" / "integration" + @dataclass class ArgparseResults: @@ -25,8 +28,13 @@ def _unit_test_context(session: Session) -> ArgparseResults: parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter ) - default_path = PROJECT_CONFIG.root_path / "test" / "unit" - parser.add_argument("directories", nargs="*", type=Path, default=[default_path]) + parser.add_argument( + "--paths", + nargs="+", + type=Path, + default=[UNIT_TESTS_DIRECTORY], + help="Paths (files or directories) to be tested", + ) parser.add_argument( "--coverage", action="store_true", help="Enable the collection of coverage data" ) @@ -37,8 +45,13 @@ def _integration_test_context(session: Session) -> ArgparseResults: parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter ) - default_path = PROJECT_CONFIG.root_path / "test" / "integration" - parser.add_argument("directories", nargs="*", type=Path, default=[default_path]) + parser.add_argument( + "--paths", + nargs="+", + type=Path, + default=[INTEGRATION_TESTS_DIRECTORY], + help="Paths (files or directories) to be tested", + ) parser.add_argument( "--coverage", action="store_true", help="Enable the collection of coverage data" ) @@ -66,7 +79,7 @@ def _test_command( ) return ( coverage_command - + ["pytest", *argparse_results.known.directories] + + ["pytest", *argparse_results.known.paths] + argparse_results.other ) From 2377517f2639857e2060bbee9284f7a275f9506b Mon Sep 17 00:00:00 2001 From: Ariel Schulz Date: Wed, 25 Nov 2026 12:45:37 +0100 Subject: [PATCH 10/18] Add tests for context functions and clean up those for test_command --- test/unit/nox/_test_test.py | 183 +++++++++++++++++++----------------- 1 file changed, 96 insertions(+), 87 deletions(-) diff --git a/test/unit/nox/_test_test.py b/test/unit/nox/_test_test.py index c1b36ad14..691398e20 100644 --- a/test/unit/nox/_test_test.py +++ b/test/unit/nox/_test_test.py @@ -1,119 +1,128 @@ -import shutil -from unittest.mock import patch +from argparse import Namespace +from pathlib import Path +from unittest.mock import Mock import pytest from exasol.toolbox.nox._test import ( + INTEGRATION_TESTS_DIRECTORY, + UNIT_TESTS_DIRECTORY, + ArgparseResults, + _integration_test_context, _test_command, - integration_tests, - unit_tests, + _unit_test_context, ) from noxconfig import PROJECT_CONFIG +PATH_CASES = [ + ([], []), + (["abc"], []), + (["abc", "def"], []), + ([], ["-s"]), + ([], ["-k", "TestClass"]), + (["abc"], ["-k", "TestClass"]), + (["abc", "def"], ["-v"]), +] -@pytest.fixture -def default_context(): - """ - The default context comes from `toolbox/nox/_shared.py::_context` - """ - return {"db_version": "8.29.13", "coverage": False, "fwd-args": []} +def _posargs(dirs, other): + if not dirs: + return other + return ["--paths", *dirs] + other -class TestTestCommand: - @staticmethod - def test_works_for_default_arguments(test_project_config_factory, default_context): - config = test_project_config_factory() - result = _test_command( - path=config.root_path / "dummy", config=config, context=default_context +class TestUnitTestContext: + @staticmethod + @pytest.mark.parametrize("dirs, other", PATH_CASES) + def test_paths_and_other_arguments(dirs, other): + result = _unit_test_context(Mock(posargs=_posargs(dirs, other))) + + assert result == ArgparseResults( + known=Namespace( + paths=[Path(d) for d in dirs] or [UNIT_TESTS_DIRECTORY], + coverage=False, + ), + other=other, ) - assert result == ["pytest", "-v", f"{config.root_path}/dummy"] - @staticmethod - def test_works_for_coverage_true(test_project_config_factory, default_context): - config = test_project_config_factory() - default_context["coverage"] = True + @pytest.mark.parametrize( + "flags, attribute, expected", + [ + (["--coverage"], "coverage", True), + ], + ) + def test_overrides_default(flags, attribute, expected): + default = getattr(_unit_test_context(Mock(posargs=[])).known, attribute) - result = _test_command( - path=config.root_path / "dummy", config=config, context=default_context - ) + result = _unit_test_context(Mock(posargs=flags)) - assert result == [ - "coverage", - "run", - "-a", - f"--rcfile={config.root_path}/pyproject.toml", - "-m", - "pytest", - "-v", - f"{config.root_path}/dummy", - ] + assert getattr(result.known, attribute) == expected + assert getattr(result.known, attribute) != default - @staticmethod - def test_works_for_fwd_args(test_project_config_factory, default_context): - config = test_project_config_factory() - default_context["fwd-args"] = ["--addition"] - result = _test_command( - path=config.root_path / "dummy", config=config, context=default_context +class TestIntegrationTestContext: + @staticmethod + @pytest.mark.parametrize("dirs, other", PATH_CASES) + def test_paths_and_other_arguments(dirs, other): + result = _integration_test_context(Mock(posargs=_posargs(dirs, other))) + + assert result == ArgparseResults( + known=Namespace( + paths=[Path(d) for d in dirs] or [INTEGRATION_TESTS_DIRECTORY], + coverage=False, + db_version=PROJECT_CONFIG.minimum_exasol_version, + ), + other=other, ) - assert result == ["pytest", "-v", f"{config.root_path}/dummy", "--addition"] + @staticmethod + @pytest.mark.parametrize( + "flags, attribute, expected", + [ + (["--coverage"], "coverage", True), + (["--db-version", "8.0.0"], "db_version", "8.0.0"), + ], + ) + def test_overrides_default(flags, attribute, expected): + default = getattr(_integration_test_context(Mock(posargs=[])).known, attribute) + result = _integration_test_context(Mock(posargs=flags)) -def test_unit_tests(nox_session, test_project_config_factory): - config = test_project_config_factory() + assert getattr(result.known, attribute) == expected + assert getattr(result.known, attribute) != default - shutil.copyfile( - PROJECT_CONFIG.root_path / "pyproject.toml", config.root_path / "pyproject.toml" - ) - test_directory = config.root_path / "test" / "unit" - test_directory.mkdir(parents=True, exist_ok=True) - test_filepath = test_directory / "dummy_test.py" - test_filepath.write_text("def test_dummy():\n assert True") - - with ( - patch("exasol.toolbox.nox._test.PROJECT_CONFIG", new=config), - patch( - "exasol.toolbox.nox._test._unit_test_context", - wraps=lambda session: {"coverage": False, "fwd-args": []}, - ) as unit_context, - ): - unit_tests(nox_session) +class TestTestCommand: + @staticmethod + def test_without_coverage(test_project_config_factory): + config = test_project_config_factory() + argparse_results = ArgparseResults( + known=Namespace(paths=[config.root_path / "dummy"], coverage=False), + other=["-v"], + ) - unit_context.assert_called_once_with(nox_session) - assert (test_directory / "__pycache__").exists() + result = _test_command(config=config, argparse_results=argparse_results) + assert result == ["pytest", config.root_path / "dummy", "-v"] -class TestIntegrationTests: @staticmethod - def test_works_without_hooks(nox_session, test_project_config_factory): + def test_with_coverage(test_project_config_factory): config = test_project_config_factory() - - shutil.copyfile( - PROJECT_CONFIG.root_path / "pyproject.toml", - config.root_path / "pyproject.toml", + argparse_results = ArgparseResults( + known=Namespace(paths=[config.root_path / "dummy"], coverage=True), + other=["-v"], ) - test_directory = config.root_path / "test" / "integration" - test_directory.mkdir(parents=True, exist_ok=True) - test_filepath = test_directory / "dummy_test.py" - test_filepath.write_text("def test_dummy():\n assert True") - - with ( - patch("exasol.toolbox.nox._test.PROJECT_CONFIG", new=config), - patch( - "exasol.toolbox.nox._test._integration_test_context", - wraps=lambda session: { - "coverage": False, - "db_version": "8.29.13", - "fwd-args": [], - }, - ) as integration_context, - ): - integration_tests(nox_session) - - integration_context.assert_called_once_with(nox_session) - assert (test_directory / "__pycache__").exists() + result = _test_command(config=config, argparse_results=argparse_results) + + assert result == [ + "coverage", + "run", + "-a", + f"--rcfile={config.root_path}/pyproject.toml", + "-m", + "pytest", + config.root_path / "dummy", + "-v", + ] From 94bda0ebe27d4e1cf841dd02f53fd417f0925c25 Mon Sep 17 00:00:00 2001 From: Ariel Schulz Date: Wed, 25 Nov 2026 12:49:19 +0100 Subject: [PATCH 11/18] Simplify command generation --- exasol/toolbox/nox/_test.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/exasol/toolbox/nox/_test.py b/exasol/toolbox/nox/_test.py index 01d46c9a0..ac2eb1fd2 100644 --- a/exasol/toolbox/nox/_test.py +++ b/exasol/toolbox/nox/_test.py @@ -66,17 +66,15 @@ def _integration_test_context(session: Session) -> ArgparseResults: def _test_command( config: BaseConfig, argparse_results: ArgparseResults ) -> Iterable[str]: - coverage_command = ( - [ + coverage_command = [] + if argparse_results.known.coverage: + coverage_command = [ "coverage", "run", "-a", f"--rcfile={config.root_path / 'pyproject.toml'}", "-m", ] - if argparse_results.known.coverage - else [] - ) return ( coverage_command + ["pytest", *argparse_results.known.paths] From db399c74ef2b311c101d58c0fed991303df94753 Mon Sep 17 00:00:00 2001 From: Ariel Schulz Date: Wed, 25 Nov 2026 12:50:24 +0100 Subject: [PATCH 12/18] Fix grammar --- exasol/toolbox/nox/_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exasol/toolbox/nox/_test.py b/exasol/toolbox/nox/_test.py index ac2eb1fd2..d15bc84ee 100644 --- a/exasol/toolbox/nox/_test.py +++ b/exasol/toolbox/nox/_test.py @@ -116,7 +116,7 @@ def unit_tests(session: Session) -> None: @nox.session(name="test:integration", python=False) def integration_tests(session: Session) -> None: """ - Runs the all integration tests + Runs all integration tests If a project needs to execute code pre-/post the test execution, it should provide appropriate hooks on their config object. From 827edcdf02d2079bd1489b88223ee75c90f7425f Mon Sep 17 00:00:00 2001 From: Ariel Schulz Date: Wed, 25 Nov 2026 12:54:20 +0100 Subject: [PATCH 13/18] Remove references to project:check --- doc/user_guide/features/index.rst | 1 - .../exasol-python-toolbox/references/common-workflows.md | 3 --- .../skills/exasol-python-toolbox/references/nox-sessions.md | 1 - test/integration/project-template/nox_test.py | 1 - test/resources/skills/exasol-python-toolbox/eval_cases.yml | 1 - 5 files changed, 7 deletions(-) diff --git a/doc/user_guide/features/index.rst b/doc/user_guide/features/index.rst index b31dfe9f7..b5cba2c14 100644 --- a/doc/user_guide/features/index.rst +++ b/doc/user_guide/features/index.rst @@ -42,7 +42,6 @@ Use :code:`nox -l` to show the current list of sessions for your project Common examples are as follows: * :code:`nox -s format:fix` applies formatting changes. -* :code:`nox -s project:check` runs the main local quality gate. * :code:`nox -s test:unit` runs unit tests. * :code:`nox -s workflow:generate -- all` updates PTB workflow files. diff --git a/exasol/toolbox/skills/exasol-python-toolbox/references/common-workflows.md b/exasol/toolbox/skills/exasol-python-toolbox/references/common-workflows.md index f08b2569e..1f9db3be2 100644 --- a/exasol/toolbox/skills/exasol-python-toolbox/references/common-workflows.md +++ b/exasol/toolbox/skills/exasol-python-toolbox/references/common-workflows.md @@ -48,9 +48,6 @@ replace it with configuration, a plugin hook, or a PTB extension point later. 2. Read the related tool sections in `pyproject.toml`. 3. Make the requested code change, document change, or configuration change. 4. Run the smallest PTB session that checks the change. -5. Run `project:check` when the change affects shared operation. -6. Run `project:check` when the change affects release readiness. -7. Run `project:check` when the change affects CI operation. When you remove or rename a documentation file, update each Sphinx `toctree` that points to it. Then run `docs:build`. diff --git a/exasol/toolbox/skills/exasol-python-toolbox/references/nox-sessions.md b/exasol/toolbox/skills/exasol-python-toolbox/references/nox-sessions.md index 063b45d39..bea2dd547 100644 --- a/exasol/toolbox/skills/exasol-python-toolbox/references/nox-sessions.md +++ b/exasol/toolbox/skills/exasol-python-toolbox/references/nox-sessions.md @@ -12,7 +12,6 @@ The sessions below match the PTB version that includes this skill. | Session | Use | Notes | | --- | --- | --- | -| `project:check` | Run large local checks or CI checks. | It runs format check, Pylint, Mypy, and coverage for unit and integration tests. | | `format:fix` | Apply Python format changes. | It runs pyupgrade, Ruff fixes, isort, and Black. | | `format:check` | Check Python format. | It runs Ruff check, isort check, and Black check. | | `lint:code` | Run static code analysis. | It runs Pylint on `PROJECT_CONFIG.source_code_path` and writes `.lint.json`. | diff --git a/test/integration/project-template/nox_test.py b/test/integration/project-template/nox_test.py index 35da03ced..90be868f4 100644 --- a/test/integration/project-template/nox_test.py +++ b/test/integration/project-template/nox_test.py @@ -7,7 +7,6 @@ EXPECTED_NOX_SESSIONS = { "format:fix", "format:check", - "project:check", "test:unit", "test:integration", "test:coverage", diff --git a/test/resources/skills/exasol-python-toolbox/eval_cases.yml b/test/resources/skills/exasol-python-toolbox/eval_cases.yml index 42b2d0e68..0715ace73 100644 --- a/test/resources/skills/exasol-python-toolbox/eval_cases.yml +++ b/test/resources/skills/exasol-python-toolbox/eval_cases.yml @@ -34,7 +34,6 @@ cases: - ".pre-commit-config.yaml" - "pre-commit" - "pre-push" - - "project:check" - "nox-sessions.md" must_not_include: - "run Pytest directly" From 4cc1911cbd63c3399c808b0f2134ee72b72b9cde Mon Sep 17 00:00:00 2001 From: Ariel Schulz Date: Wed, 25 Nov 2026 12:55:45 +0100 Subject: [PATCH 14/18] Remove references to test:coverage --- .../skills/exasol-python-toolbox/references/nox-sessions.md | 1 - .../skills/exasol-python-toolbox/references/source-routing.md | 3 +-- test/integration/project-template/nox_test.py | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/exasol/toolbox/skills/exasol-python-toolbox/references/nox-sessions.md b/exasol/toolbox/skills/exasol-python-toolbox/references/nox-sessions.md index bea2dd547..ccb12fc38 100644 --- a/exasol/toolbox/skills/exasol-python-toolbox/references/nox-sessions.md +++ b/exasol/toolbox/skills/exasol-python-toolbox/references/nox-sessions.md @@ -31,7 +31,6 @@ The sessions below match the PTB version that includes this skill. | --- | --- | --- | | `test:unit` | Run unit tests. | It runs `pytest -v test/unit`. Put Pytest options after `--`; use `-k` to select tests by name. | | `test:integration` | Run integration tests. | It runs `pytest -v test/integration`. It supports PTB integration test hooks. | -| `test:coverage` | Run all tests with coverage. | It runs unit and integration tests with coverage. It prints `coverage report -m`. | Test command examples: diff --git a/exasol/toolbox/skills/exasol-python-toolbox/references/source-routing.md b/exasol/toolbox/skills/exasol-python-toolbox/references/source-routing.md index 185c714d6..3a64b31cc 100644 --- a/exasol/toolbox/skills/exasol-python-toolbox/references/source-routing.md +++ b/exasol/toolbox/skills/exasol-python-toolbox/references/source-routing.md @@ -36,8 +36,7 @@ Read the source file before you explain a detailed rule. - `exasol/toolbox/nox/_package.py`: package validation. - `exasol/toolbox/nox/_release.py`: release preparation, release update, and release trigger sessions. -- `exasol/toolbox/nox/_test.py`: `test:unit`, `test:integration`, and - `test:coverage`. +- `exasol/toolbox/nox/_test.py`: `test:unit` and `test:integration` - `exasol/toolbox/nox/_workflow.py`: workflow check, generation, and audit sessions. diff --git a/test/integration/project-template/nox_test.py b/test/integration/project-template/nox_test.py index 90be868f4..1dc0aae58 100644 --- a/test/integration/project-template/nox_test.py +++ b/test/integration/project-template/nox_test.py @@ -9,7 +9,6 @@ "format:check", "test:unit", "test:integration", - "test:coverage", "lint:code", "lint:typing", "lint:security", From 673c36db1d8a3337b90e6326b7821368abc353d8 Mon Sep 17 00:00:00 2001 From: Ariel Schulz Date: Wed, 25 Nov 2026 13:00:41 +0100 Subject: [PATCH 15/18] Add changelog entries --- doc/changes/unreleased.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/doc/changes/unreleased.md b/doc/changes/unreleased.md index b9a20bf05..6d337da01 100644 --- a/doc/changes/unreleased.md +++ b/doc/changes/unreleased.md @@ -2,10 +2,19 @@ ## Summary -Raised the minimum supported Python version from 3.11 to 3.11.5, as later versions of -`soupsieve` no longer support earlier patch releases and the vulnerability in -`soupsieve` for Python 3.11 could not otherwise be resolved. +In this major release, we: + +* Dropped the Nox sessions `test:coverage` and `project:check` +* Modified the Nox sessions `test:unit` and `test:integration` to accept one or more + files or directories via `--paths` +* Raised the minimum supported Python version from 3.11 to 3.11.5, as later versions of + `soupsieve` no longer support earlier patch releases and the vulnerability in + `soupsieve` for Python 3.11 could not otherwise be resolved. ## Refactoring * #998: Raised `requires-python` to `>=3.11.5,<4.0` +* #939: + * Removed Nox session `test:coverage` + * Removed Nox session `project:check` + * Modified Nox sessions `test:unit` and `test:integration` to accept one or more files or directories via `--paths`, overriding the default test directory From 7a44ad38963d174b082bcdb9846c57c0c1ed2e90 Mon Sep 17 00:00:00 2001 From: Ariel Schulz Date: Wed, 25 Nov 2026 13:13:12 +0100 Subject: [PATCH 16/18] Re-add test for integration hook behavior --- test/unit/nox/_test_test.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/test/unit/nox/_test_test.py b/test/unit/nox/_test_test.py index 691398e20..466d1386e 100644 --- a/test/unit/nox/_test_test.py +++ b/test/unit/nox/_test_test.py @@ -1,6 +1,8 @@ from argparse import Namespace from pathlib import Path -from unittest.mock import Mock +from unittest.mock import ( + Mock, +) import pytest @@ -9,9 +11,11 @@ UNIT_TESTS_DIRECTORY, ArgparseResults, _integration_test_context, + _integration_tests, _test_command, _unit_test_context, ) +from exasol.toolbox.nox.plugin import hookimpl from noxconfig import PROJECT_CONFIG PATH_CASES = [ @@ -126,3 +130,34 @@ def test_with_coverage(test_project_config_factory): config.root_path / "dummy", "-v", ] + + +class RecordingPlugin: + calls: list[str] = [] + + @hookimpl + def pre_integration_tests_hook(self, session, config, context): + self.calls.append("pre") + + @hookimpl + def post_integration_tests_hook(self, session, config, context): + self.calls.append("post") + + +class TestIntegrationTests: + @staticmethod + def test_hooks_wrap_test_command(test_project_config_factory): + RecordingPlugin.calls = [] + config = test_project_config_factory( + plugins_for_nox_sessions=(RecordingPlugin,) + ) + argparse_results = ArgparseResults( + known=Namespace(paths=[Path("dummy")], coverage=False), other=[] + ) + session = Mock() + session.run.side_effect = lambda *a, **kw: RecordingPlugin.calls.append("run") + + _integration_tests(session, config, argparse_results) + + session.run.assert_called_once_with("pytest", Path("dummy")) + assert RecordingPlugin.calls == ["pre", "run", "post"] From ade276e4629870a77fd69351782d16640fce7a96 Mon Sep 17 00:00:00 2001 From: Ariel Schulz Date: Wed, 25 Nov 2026 13:17:43 +0100 Subject: [PATCH 17/18] Remove unneeded line; fix Sonar --- test/unit/nox/_test_test.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/unit/nox/_test_test.py b/test/unit/nox/_test_test.py index 466d1386e..83dacc3e6 100644 --- a/test/unit/nox/_test_test.py +++ b/test/unit/nox/_test_test.py @@ -146,8 +146,7 @@ def post_integration_tests_hook(self, session, config, context): class TestIntegrationTests: @staticmethod - def test_hooks_wrap_test_command(test_project_config_factory): - RecordingPlugin.calls = [] + def test_hooks_wrap_test_command(test_project_config_factory, monkeypatch): config = test_project_config_factory( plugins_for_nox_sessions=(RecordingPlugin,) ) From 368cf704d62d661785a2c63deae4a275852149ee Mon Sep 17 00:00:00 2001 From: Ariel Schulz Date: Wed, 25 Nov 2026 14:49:04 +0100 Subject: [PATCH 18/18] Add docstring --- exasol/toolbox/nox/_test.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/exasol/toolbox/nox/_test.py b/exasol/toolbox/nox/_test.py index d15bc84ee..1c9d60ffa 100644 --- a/exasol/toolbox/nox/_test.py +++ b/exasol/toolbox/nox/_test.py @@ -20,6 +20,12 @@ @dataclass class ArgparseResults: + """ + Records the results from the parsed session parameters. + Argparse separates these based on which arguments are expected (`known`) + and which are unknown (`other`). + """ + known: argparse.Namespace other: list[str]