1+ import importlib
2+ import json
13import os
24import sys
35from typing import Any
46
57import pytest
68
7- # Ensure test/core/ is on sys.path so run_tests and metaflow_test are importable.
9+ from metaflow_test import MetaflowTest
10+ from metaflow_test .formatter import FlowFormatter
11+
12+ # Ensure test/core/ is on sys.path so metaflow_test is importable.
813_CORE_DIR = os .path .dirname (os .path .abspath (__file__ ))
914if _CORE_DIR not in sys .path :
1015 sys .path .insert (0 , _CORE_DIR )
1116
1217
18+ # ---------------------------------------------------------------------------
19+ # Test discovery — owned by pytest, no dependency on run_tests.py
20+ # ---------------------------------------------------------------------------
21+
22+
23+ def _iter_graphs ():
24+ root = os .path .join (_CORE_DIR , "graphs" )
25+ for graphfile in os .listdir (root ):
26+ if graphfile .endswith (".json" ) and not graphfile [0 ] == "." :
27+ with open (os .path .join (root , graphfile )) as f :
28+ yield json .load (f )
29+
30+
31+ def _iter_tests ():
32+ root = os .path .join (_CORE_DIR , "tests" )
33+ if root not in sys .path :
34+ sys .path .insert (0 , root )
35+ for testfile in os .listdir (root ):
36+ if testfile .endswith (".py" ) and not testfile [0 ] == "." :
37+ mod = importlib .import_module (testfile [:- 3 ], "metaflow_test" )
38+ for name in dir (mod ):
39+ obj = getattr (mod , name )
40+ if (
41+ name != "MetaflowTest"
42+ and isinstance (obj , type )
43+ and issubclass (obj , MetaflowTest )
44+ ):
45+ yield obj ()
46+
47+
48+ # ---------------------------------------------------------------------------
49+ # pytest hooks
50+ # ---------------------------------------------------------------------------
51+
52+
1353def pytest_addoption (parser : Any ) -> None :
1454 parser .addoption (
1555 "--core-tests" ,
@@ -28,9 +68,6 @@ def pytest_generate_tests(metafunc: Any) -> None:
2868 return
2969
3070 try :
31- from run_tests import iter_graphs , iter_tests
32- from metaflow_test .formatter import FlowFormatter
33-
3471 ok_tests_raw = metafunc .config .getoption ("--core-tests" , default = None )
3572 ok_graphs_raw = metafunc .config .getoption ("--core-graphs" , default = None )
3673 ok_tests = (
@@ -54,8 +91,8 @@ def pytest_generate_tests(metafunc: Any) -> None:
5491 disable_parallel = os .environ .get ("METAFLOW_CORE_DISABLE_PARALLEL" , "" ) == "1"
5592
5693 mark = getattr (pytest .mark , marker_name )
57- all_tests = sorted (iter_tests (), key = lambda t : t .PRIORITY )
58- all_graphs = list (iter_graphs ())
94+ all_tests = sorted (_iter_tests (), key = lambda t : t .PRIORITY )
95+ all_graphs = list (_iter_graphs ())
5996
6097 params = []
6198 for graph in all_graphs :
0 commit comments