11# Run nox tests
22#
33# usage:
4- # uv run --locked nox --error-on-external-run --reuse-venv=yes --non-interactive
4+ # uv run --locked nox --error-on-external-run --reuse-venv=no --non-interactive
55#
66# If you want to target a specific Python version, add -p parameter
77from __future__ import annotations
1414PREFIX_TESTS_UNIT = "tests/unit"
1515
1616
17- def build_and_run_test (session : nox .Session , folders : list , extras : str = "" ) -> None :
17+ def build_and_run_test (
18+ session : nox .Session ,
19+ folders : list ,
20+ extras : str = "" ,
21+ pytest_args : tuple [str , ...] = (),
22+ ) -> None :
1823 """
1924 This function is responsible for setting up the testing environment and running the test suite for specific feature.
2025
@@ -32,20 +37,29 @@ def build_and_run_test(session: nox.Session, folders: list, extras: str = "") ->
3237 extras: Optional[str]
3338 A string representing additional dependencies that should be installed for the test environment.
3439 If not provided, the function will install the project with basic dependencies
40+ pytest_args: tuple[str, ...]
41+ Additional pytest arguments for selecting tests with matching dependencies
3542 """
3643
3744 # Required install to execute any test
38- # Shared fixtures use JSON Schema validation; previously Poetry installed it transitively.
39- session .install ("pytest" , "pytest-mock" , "pytest_socket" , "pytest-asyncio" , "fastjsonschema" )
45+ session .install ("pytest" , "pytest-mock" , "pytest_socket" , "pytest-asyncio" )
4046
4147 # Powertools project folder is in the root
4248 if extras :
4349 session .install (f"./[{ extras } ]" )
4450 else :
4551 session .install ("./" )
52+ session .run (
53+ "python" ,
54+ "-I" ,
55+ "-c" ,
56+ "from importlib.util import find_spec; "
57+ "assert find_spec('fastjsonschema') is None, "
58+ "'fastjsonschema leaked into the required-dependencies environment'" ,
59+ )
4660
4761 # Execute test in specific folders
48- session .run ("pytest" , * folders )
62+ session .run ("pytest" , * folders , * pytest_args )
4963
5064
5165@nox .session ()
@@ -72,6 +86,7 @@ def test_with_only_required_packages(session: nox.Session):
7286 f"{ PREFIX_TESTS_FUNCTIONAL } /batch/required_dependencies/" ,
7387 f"{ PREFIX_TESTS_FUNCTIONAL } /kafka_consumer/required_dependencies/" ,
7488 ],
89+ pytest_args = ("-m" , "not requires_validation" ),
7590 )
7691
7792
@@ -121,6 +136,7 @@ def test_with_boto3_sdk_as_required_package(session: nox.Session):
121136 f"{ PREFIX_TESTS_FUNCTIONAL } /idempotency/_boto3/" ,
122137 ],
123138 extras = "aws-sdk" ,
139+ pytest_args = ("-m" , "not requires_validation" ),
124140 )
125141
126142
@@ -132,8 +148,10 @@ def test_with_fastjsonschema_as_required_package(session: nox.Session):
132148 session ,
133149 folders = [
134150 f"{ PREFIX_TESTS_FUNCTIONAL } /validator/_fastjsonschema/" ,
151+ f"{ PREFIX_TESTS_FUNCTIONAL } /event_handler/required_dependencies/test_api_middlewares.py" ,
135152 ],
136153 extras = "validation" ,
154+ pytest_args = ("-m" , "requires_validation" ),
137155 )
138156
139157
@@ -170,6 +188,29 @@ def test_with_pydantic_required_package(session: nox.Session):
170188 f"{ PREFIX_TESTS_UNIT } /event_handler/_pydantic/" ,
171189 ],
172190 extras = "parser" ,
191+ pytest_args = ("-m" , "not requires_validation" ),
192+ )
193+
194+
195+ @nox .session ()
196+ def test_with_parser_and_validation_required_packages (session : nox .Session ):
197+ """Validate generated OpenAPI schemas with Parser and Validation dependencies."""
198+ build_and_run_test (
199+ session ,
200+ folders = [f"{ PREFIX_TESTS_FUNCTIONAL } /event_handler/_pydantic/" ],
201+ extras = "parser,validation" ,
202+ pytest_args = ("-m" , "requires_validation" ),
203+ )
204+
205+
206+ @nox .session ()
207+ def test_with_boto3_and_validation_required_packages (session : nox .Session ):
208+ """Test Idempotency combined with the Validation decorator."""
209+ build_and_run_test (
210+ session ,
211+ folders = [f"{ PREFIX_TESTS_FUNCTIONAL } /idempotency/_boto3/" ],
212+ extras = "aws-sdk,validation" ,
213+ pytest_args = ("-m" , "requires_validation" ),
173214 )
174215
175216
0 commit comments