Skip to content

Commit 915a82d

Browse files
ssjiaSS-JIA
authored andcommitted
[devtools][tests][4/N] Report disabled inspector tests as executed
Applies the same disabled-test treatment as the prior diffs in this stack to the devtools inspector tests. Some test runners preserve stale failure state when tests report through unittest skip results, so this replaces the conditionally disabled coverage with a local decorator that keeps the tests discoverable, logs their disabled reason, and produces an executed result. Adds a disable_if decorator that mirrors unittest.skipIf (evaluating the condition at decoration time) and converts the three Windows-gated test cases to use it. Differential Revision: [D106736354](https://our.internmc.facebook.com/intern/diff/D106736354/) ghstack-source-id: 387629542 Pull-Request: pytorch#19874
1 parent d1c80af commit 915a82d

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

devtools/inspector/tests/inspector_test.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# pyre-unsafe
88

99
import copy
10+
import functools
1011
import os
1112
import random
1213
import statistics
@@ -90,6 +91,28 @@ def forward(self, indices: torch.Tensor, values: torch.Tensor) -> torch.Tensor:
9091
ETRECORD_PATH = "unittest_etrecord_path"
9192

9293

94+
def disable_if(condition, reason):
95+
"""Disable a test when condition is true, still reporting it as executed.
96+
97+
Conditional analogue of unittest.skipIf that keeps disabled tests visible in
98+
logs instead of producing a skipped result, which some test runners handle
99+
inconsistently.
100+
"""
101+
102+
def decorator(fn):
103+
if not condition:
104+
return fn
105+
106+
@functools.wraps(fn)
107+
def wrapper(*args, **kwargs):
108+
print(f"DISABLED_TEST: {fn.__qualname__}: {reason}")
109+
return None
110+
111+
return wrapper
112+
113+
return decorator
114+
115+
93116
# TODO: write an E2E test: create an inspector instance, mock just the file reads, and then verify the external correctness
94117
class TestInspector(unittest.TestCase):
95118
def test_perf_data(self) -> None:
@@ -1504,7 +1527,7 @@ def test_calculate_numeric_gap_with_edge_dialect_exported_program_name(self):
15041527
self.assertIsInstance(df, pd.DataFrame)
15051528
self.assertEqual(len(df), 1)
15061529

1507-
@unittest.skipIf(sys.platform.startswith("win"), "Skipping on Windows")
1530+
@disable_if(sys.platform.startswith("win"), "Skipping on Windows")
15081531
def test_transformer_block_xnnpack_numeric_gap_within_tolerance(self):
15091532
"""
15101533
Test that the numeric gap between AOT and runtime intermediate outputs
@@ -1693,7 +1716,7 @@ def forward(
16931716
f"Stack trace for {op_name} doesn't contain file info",
16941717
)
16951718

1696-
@unittest.skipIf(sys.platform.startswith("win"), "Skipping on Windows")
1719+
@disable_if(sys.platform.startswith("win"), "Skipping on Windows")
16971720
def test_intermediate_tensor_comparison_with_torch_export(self):
16981721
"""Test intermediate tensor comparison using torch.export.export and to_edge_transform_and_lower.
16991722
@@ -1840,7 +1863,7 @@ def _gen_random_runtime_output(
18401863
) -> List[Union[None, List[torch.Tensor], bool, float, int, str, torch.Tensor]]:
18411864
return [torch.randn(RAW_DATA_SIZE)]
18421865

1843-
@unittest.skipIf(sys.platform.startswith("win"), "Skipping on Windows")
1866+
@disable_if(sys.platform.startswith("win"), "Skipping on Windows")
18441867
def test_disable_debug_handle_validation_with_symbolic_shapes(self):
18451868
"""
18461869
Test that demonstrates the issue with symbolic shape related nodes losing from_node info

0 commit comments

Comments
 (0)