Repository navigation
Refactoring/939 modify nox test session to allow path specification #999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ArBridgeman
merged 18 commits into
main
from
refactoring/939-modify-nox-test-session-to-allow-path-specification
Nov 25, 2026
+218
−290
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
cb00878
Removed unnecessary method
ArBridgeman 6ed1105
Modify Nox session test:* to allow path specification
ArBridgeman acbb2fd
Remove unused project:check and test:coverage (as not properly implem…
ArBridgeman 66d0cc5
Reduce tests to necessary ones
ArBridgeman cb855fe
Move functions out of _shared
ArBridgeman 7b96009
Move tests to new location and redistribute per function tested
ArBridgeman e518f4b
Consolidate unit_test into nox session
ArBridgeman 73a1ad3
Fix with imports
ArBridgeman 2173df7
Switch from positional to keyword and clarify a path is allowed (coul…
ArBridgeman 2377517
Add tests for context functions and clean up those for test_command
ArBridgeman 94bda0e
Simplify command generation
ArBridgeman db399c7
Fix grammar
ArBridgeman 827edcd
Remove references to project:check
ArBridgeman 4cc1911
Remove references to test:coverage
ArBridgeman 673c36d
Add changelog entries
ArBridgeman 7a44ad3
Re-add test for integration hook behavior
ArBridgeman ade276e
Remove unneeded line; fix Sonar
ArBridgeman 368cf70
Add docstring
ArBridgeman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,104 +1,133 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| from collections.abc import ( | ||
| Iterable, | ||
| MutableMapping, | ||
| ) | ||
| from dataclasses import dataclass | ||
| 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 ( | ||
| _integration_test_context, | ||
| _unit_test_context, | ||
| ) | ||
| from exasol.toolbox.nox.plugin import NoxTasks | ||
| from noxconfig import ( | ||
| PROJECT_CONFIG, | ||
| ) | ||
| 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: | ||
| """ | ||
| 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] | ||
|
|
||
|
|
||
| def _unit_test_context(session: Session) -> ArgparseResults: | ||
| parser = argparse.ArgumentParser( | ||
| formatter_class=argparse.ArgumentDefaultsHelpFormatter | ||
| ) | ||
| 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" | ||
| ) | ||
| return ArgparseResults(*parser.parse_known_args(session.posargs)) | ||
|
|
||
|
|
||
| def _integration_test_context(session: Session) -> ArgparseResults: | ||
| parser = argparse.ArgumentParser( | ||
| formatter_class=argparse.ArgumentDefaultsHelpFormatter | ||
| ) | ||
| 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" | ||
| ) | ||
| 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( | ||
| path: Path, config: BaseConfig, context: MutableMapping[str, Any] | ||
| 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 context["coverage"] | ||
| else [] | ||
| return ( | ||
| coverage_command | ||
| + ["pytest", *argparse_results.known.paths] | ||
| + argparse_results.other | ||
| ) | ||
| pytest_command = ["pytest", "-v", f"{path}"] | ||
| return coverage_command + pytest_command + context["fwd-args"] | ||
|
|
||
|
|
||
| def _unit_tests( | ||
| session: Session, config: BaseConfig, context: MutableMapping[str, Any] | ||
| ) -> None: | ||
| command = _test_command(config.root_path / "test" / "unit", config, context) | ||
| 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) | ||
|
|
||
|
|
||
| def _coverage( | ||
| session: Session, config: BaseConfig, context: MutableMapping[str, Any] | ||
| ) -> 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) | ||
| session.run(*command) | ||
| pm.hook.post_integration_tests_hook( | ||
| session=session, config=config, context=argparse_results | ||
| ) | ||
|
|
||
|
|
||
| @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) | ||
| argparse_results = _unit_test_context(session) | ||
| command = _test_command(PROJECT_CONFIG, argparse_results) | ||
| session.run(*command) | ||
|
|
||
|
|
||
| @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. | ||
| * 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 | ||
| """ | ||
| context = _integration_test_context(session) | ||
| _integration_tests(session, PROJECT_CONFIG, context) | ||
|
|
||
|
|
||
| @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) | ||
| argparse_results = _integration_test_context(session) | ||
| _integration_tests(session, PROJECT_CONFIG, argparse_results) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.