Skip to content

Commit bc069d5

Browse files
Suppress PytestCollectionWarning for non-test classes (pytorch#18192)
Fixes pytorch#18175 Added `__test__ = False` to non-test classes that pytest was incorrectly trying to collect as test classes, causing pages of PytestCollectionWarning output. Classes fixed: - `TestResult`, `TestCaseSummary`, `TestSessionState` in `backends/test/suite/reporting.py` - `Tester` in `backends/xnnpack/test/tester/tester.py` - `TestCat` in `exir/tests/test_prune_empty_tensors_pass.py` - `TestModel1` in `exir/tests/test_remove_view_copy.py` ### Test plan Ran `pytest --collect-only` before and after the changes. Before: multiple PytestCollectionWarning lines for each of these classes. After: 0 warnings found. To verify: ```bash pytest --collect-only 2>&1 | python -c "import sys; lines=[l for l in sys.stdin if 'PytestCollectionWarning' in l]; print(f'{len(lines)} warnings found')"
1 parent 69ae8c5 commit bc069d5

4 files changed

Lines changed: 12 additions & 0 deletions

File tree

backends/test/suite/reporting.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
class TestResult(IntEnum):
6161
"""Represents the result of a test case run, indicating success or a specific failure reason."""
6262

63+
__test__ = False
64+
6365
SUCCESS = 0
6466
""" The test succeeded with the backend delegate part or all of the graph. """
6567

@@ -155,6 +157,8 @@ class TestCaseSummary:
155157
Contains summary results for the execution of a single test case.
156158
"""
157159

160+
__test__ = False
161+
158162
backend: str
159163
""" The name of the target backend. """
160164

@@ -210,6 +214,8 @@ def is_delegated(self):
210214

211215
@dataclass
212216
class TestSessionState:
217+
__test__ = False
218+
213219
seed: int
214220

215221
# True if the CSV header has been written to report__path.

backends/xnnpack/test/tester/tester.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ class ToExecutorch(BaseStages.ToExecutorch):
102102

103103

104104
class Tester(TesterBase):
105+
__test__ = False
106+
105107
def __init__(
106108
self,
107109
module: torch.nn.Module,

exir/tests/test_prune_empty_tensors_pass.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616

1717
class TestCat(nn.Module):
18+
__test__ = False
19+
1820
def forward(self, x, y, z):
1921
empty = torch.empty((0, 6))
2022
return torch.cat([empty, x, empty, y, z, empty])

exir/tests/test_remove_view_copy.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616

1717
class TestModel1(nn.Module):
18+
__test__ = False
19+
1820
def __init__(self):
1921
super().__init__()
2022
self.parameter = nn.Parameter(torch.rand(5, 6))

0 commit comments

Comments
 (0)