@@ -72,6 +72,13 @@ def pytest_addoption(parser: Parser) -> None:
7272 help = "Run tests for this fork only (e.g., --fork Osaka)" ,
7373 )
7474
75+ parser .addoption (
76+ "--tests-file" ,
77+ dest = "tests_path" ,
78+ type = Path ,
79+ help = "Path to a file containing test ids, one per line" ,
80+ )
81+
7582
7683def pytest_configure (config : Config ) -> None :
7784 """
@@ -92,8 +99,7 @@ def pytest_configure(config: Config) -> None:
9299 ethereum .trace .set_evm_trace (Eip3155Tracer ())
93100
94101
95- def pytest_collection_modifyitems (config : Config , items : list [Item ]) -> None :
96- """Filter test items based on the specified fork option."""
102+ def _fork_collection_modifyitems (config : Config , items : list [Item ]) -> None :
97103 desired_fork = config .getoption ("fork" , None )
98104 if not desired_fork :
99105 return
@@ -125,6 +131,36 @@ def pytest_collection_modifyitems(config: Config, items: list[Item]) -> None:
125131 items [:] = selected # keep only what matches
126132
127133
134+ def _tests_path_collection_modifyitems (
135+ config : Config , items : list [Item ]
136+ ) -> None :
137+ tests_path = config .getoption ("tests_path" , None )
138+ if tests_path is None :
139+ return
140+
141+ with open (tests_path ) as f :
142+ test_ids = set (x [:- 1 ] for x in f .readlines ())
143+
144+ selected = []
145+ deselected = []
146+ for item in items :
147+ if item .nodeid in test_ids :
148+ selected .append (item )
149+ test_ids .remove (item .nodeid )
150+ else :
151+ deselected .append (item )
152+
153+ if deselected :
154+ config .hook .pytest_deselected (items = deselected )
155+ items [:] = selected # keep only what matches
156+
157+
158+ def pytest_collection_modifyitems (config : Config , items : list [Item ]) -> None :
159+ """Filter test items."""
160+ _fork_collection_modifyitems (config , items )
161+ _tests_path_collection_modifyitems (config , items )
162+
163+
128164class _FixturesDownloader :
129165 cache : Final [SQLiteCache ]
130166 session : Final [CachedSession ]
0 commit comments