1+ import pytest
12from infrahub_sdk .client import Config as InfrahubClientConfig
23from infrahub_sdk .client import InfrahubClientSync
34from infrahub_sdk .node import InfrahubNodeSync
4- from pytest import Config , Item , Session , TestReport
55
66from infrahub .core .constants import InfrahubKind
77from infrahub .core .timestamp import Timestamp
@@ -50,7 +50,12 @@ def get_repository_validator(self) -> tuple[InfrahubNodeSync, bool]:
5050
5151 return validator , True
5252
53- def pytest_collection_modifyitems (self , session : Session , config : Config , items : list [Item ]) -> None : # noqa: ARG002
53+ def pytest_collection_modifyitems (
54+ self ,
55+ session : pytest .Session , # noqa: ARG002
56+ config : pytest .Config , # noqa: ARG002
57+ items : list [pytest .Item ],
58+ ) -> None :
5459 """This function is called after item collection and gives the opportunity to work on the collection before sending the items for testing.
5560
5661 All items without an "infrahub" marker will be discarded. Items will also be re-ordered to be run in a specific order:
@@ -62,7 +67,7 @@ def pytest_collection_modifyitems(self, session: Session, config: Config, items:
6267 """
6368 filtered_items = [i for i in items if i .get_closest_marker ("infrahub" )]
6469
65- def sort_key (item : Item ) -> tuple [int , int ]:
70+ def sort_key (item : pytest . Item ) -> tuple [int , int ]:
6671 type_cost = 99
6772 for marker_name , priority in ORDER_TYPE_MAP .items ():
6873 if item .get_closest_marker (marker_name ):
@@ -80,7 +85,7 @@ def sort_key(item: Item) -> tuple[int, int]:
8085 filtered_items .sort (key = sort_key )
8186 items [:] = filtered_items
8287
83- def pytest_collection_finish (self , session : Session ) -> None : # noqa: ARG002
88+ def pytest_collection_finish (self , session : pytest . Session ) -> None : # noqa: ARG002
8489 """This function is called when tests have been collected and modified, meaning they are ready to be run."""
8590 self .proposed_change = self .client .get (kind = InfrahubKind .PROPOSEDCHANGE , id = self .proposed_change_id )
8691 self .proposed_change .validations .fetch ()
@@ -93,7 +98,7 @@ def pytest_collection_finish(self, session: Session) -> None: # noqa: ARG002
9398 check = relationship .peer
9499 self .checks [check .origin .value ] = check
95100
96- def pytest_runtestloop (self , session : Session ) -> object | None : # noqa: ARG002
101+ def pytest_runtestloop (self , session : pytest . Session ) -> object | None : # noqa: ARG002
97102 """This function is called when the test loop is being run."""
98103 self .validator .conclusion .value = "unknown"
99104 self .validator .state .value = "in_progress"
@@ -102,7 +107,7 @@ def pytest_runtestloop(self, session: Session) -> object | None: # noqa: ARG002
102107
103108 return None
104109
105- def pytest_runtest_setup (self , item : Item ) -> None :
110+ def pytest_runtest_setup (self , item : pytest . Item ) -> None :
106111 """Create a StandardCheck for each test item to later record its details.
107112
108113 If a check already exists, reset it to its default values.
@@ -130,7 +135,7 @@ def pytest_runtest_setup(self, item: Item) -> None:
130135
131136 check .save ()
132137
133- def pytest_runtest_logreport (self , report : TestReport ) -> None :
138+ def pytest_runtest_logreport (self , report : pytest . TestReport ) -> None :
134139 """This function is called 3 times per test: setup, call, teardown."""
135140 if report .when != "call" :
136141 return
@@ -142,7 +147,7 @@ def pytest_runtest_logreport(self, report: TestReport) -> None:
142147 # Workaround for https://github.com/opsmill/infrahub/issues/2184
143148 check .update (do_full_update = True )
144149
145- def pytest_sessionfinish (self , session : Session ) -> None : # noqa: ARG002
150+ def pytest_sessionfinish (self , session : pytest . Session ) -> None : # noqa: ARG002
146151 """Set the final RepositoryValidator details after completing the test session."""
147152 conclusion = "success"
148153
0 commit comments