File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2525 "add_environment_test" ,
2626 "add_submission_test" ,
2727 "run_tests" ,
28+ "suppress_run_tests" ,
2829 # Process
2930 "drop_privileges" ,
3031 "run" ,
5758 environment_test ,
5859 run_tests ,
5960 submission_test ,
61+ suppress_run_tests ,
6062)
6163from .process import (
6264 drop_privileges ,
Original file line number Diff line number Diff line change 1111
1212DEFAULT_TASK_NAME = "default"
1313__registered_tasks : ty .Dict [str , "_Task" ] = {}
14+ _suppress_run_tests : bool = False
1415
1516
1617@dataclass
@@ -124,6 +125,12 @@ def wrapper(*args: str, **kwargs: Any) -> Any:
124125 return _extended_submission_test
125126
126127
128+ def suppress_run_tests (suppress : bool = True ) -> None :
129+ """Suppress run_tests() calls (used by task.py to prevent double execution)."""
130+ global _suppress_run_tests
131+ _suppress_run_tests = suppress
132+
133+
127134def run_tests (
128135 * ,
129136 result_will_be_submitted : bool = False ,
@@ -139,6 +146,16 @@ def run_tests(
139146 Returns:
140147 A list of TaskTestResult objects containing the results of each task.
141148 """
149+ if _suppress_run_tests :
150+ warnings .warn (
151+ "Calling rf.run_tests() at the end of submission_tests is deprecated "
152+ "and will be removed in a future version. "
153+ "Remove the rf.run_tests() call; tests are executed automatically." ,
154+ DeprecationWarning ,
155+ stacklevel = 2 ,
156+ )
157+ return []
158+
142159 # Set env var so test_result_will_be_submitted() works within tests
143160 if result_will_be_submitted :
144161 os .environ ["RESULT_WILL_BE_SUBMITTED" ] = "1"
Original file line number Diff line number Diff line change 1717 extended_submission_test ,
1818 run_tests ,
1919 submission_test ,
20+ suppress_run_tests ,
2021)
2122from ref_utils .error import RefUtilsError
2223
@@ -394,3 +395,23 @@ def sub_test() -> bool:
394395 assert isinstance (results , list )
395396 assert len (results ) == 1
396397 assert isinstance (results [0 ], TaskTestResult )
398+
399+ def test_suppress_run_tests_returns_empty_with_warning (self ) -> None :
400+ """Test that run_tests() emits a deprecation warning when suppressed."""
401+
402+ @submission_test ()
403+ def sub_test () -> bool :
404+ return True
405+
406+ suppress_run_tests (True )
407+ try :
408+ with warnings .catch_warnings (record = True ) as w :
409+ warnings .simplefilter ("always" )
410+ results = run_tests ()
411+
412+ assert results == []
413+ assert len (w ) == 1
414+ assert issubclass (w [0 ].category , DeprecationWarning )
415+ assert "deprecated" in str (w [0 ].message ).lower ()
416+ finally :
417+ suppress_run_tests (False )
You can’t perform that action at this time.
0 commit comments