Skip to content

Commit 12d00ce

Browse files
hjmjohnsonericspod
andauthored
Cleanup warnings when collecting tests (#7914)
Minimize warning information so that important warnings and errors are more easily accessible warnings identified with ```bash python3 -W ignore::DeprecationWarning -m pytest -k dummy ``` Fixing warnings like: cannot collect test class 'TestTimeAugmentation' because it has a __init__ constructor Use `__test__ = False` to suppress attempted collection in those non test-classes ### Description A few sentences describing the changes proposed in this pull request. ### Types of changes - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [x] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. Signed-off-by: Hans Johnson <[email protected]> Co-authored-by: Eric Kerfoot <[email protected]>
1 parent 316934a commit 12d00ce

12 files changed

+19
-0
lines changed

monai/data/test_time_augmentation.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ class TestTimeAugmentation:
106106
mode, mean, std, vvc = tt_aug(test_data)
107107
"""
108108

109+
__test__ = False # indicate to pytest that this class is not intended for collection
110+
109111
def __init__(
110112
self,
111113
transform: InvertibleTransform,

tests/test_arraydataset.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141

4242
class TestCompose(Compose):
43+
__test__ = False # indicate to pytest that this class is not intended for collection
4344

4445
def __call__(self, input_, lazy=False):
4546
img = self.transforms[0](input_)

tests/test_auto3dseg.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ class TestOperations(Operations):
123123
Test example for user operation
124124
"""
125125

126+
__test__ = False # indicate to pytest that this class is not intended for collection
127+
126128
def __init__(self) -> None:
127129
self.data = {"max": np.max, "mean": np.mean, "min": np.min}
128130

@@ -132,6 +134,8 @@ class TestAnalyzer(Analyzer):
132134
Test example for a simple Analyzer
133135
"""
134136

137+
__test__ = False # indicate to pytest that this class is not intended for collection
138+
135139
def __init__(self, key, report_format, stats_name="test"):
136140
self.key = key
137141
super().__init__(stats_name, report_format)
@@ -149,6 +153,8 @@ class TestImageAnalyzer(Analyzer):
149153
Test example for a simple Analyzer
150154
"""
151155

156+
__test__ = False # indicate to pytest that this class is not intended for collection
157+
152158
def __init__(self, image_key="image", stats_name="test_image"):
153159
self.image_key = image_key
154160
report_format = {"test_stats": None}

tests/test_convert_data_type.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373

7474

7575
class TestTensor(torch.Tensor):
76+
__test__ = False # indicate to pytest that this class is not intended for collection
7677
pass
7778

7879

tests/test_handler_prob_map_producer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131

3232
class TestDataset(Dataset):
33+
__test__ = False # indicate to pytest that this class is not intended for collection
3334

3435
def __init__(self, name, size):
3536
super().__init__(
@@ -64,6 +65,7 @@ def __getitem__(self, index):
6465

6566

6667
class TestEvaluator(Evaluator):
68+
__test__ = False # indicate to pytest that this class is not intended for collection
6769

6870
def _iteration(self, engine, batchdata):
6971
return batchdata

tests/test_handler_validation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323

2424
class TestEvaluator(Evaluator):
25+
__test__ = False # indicate to pytest that this class is not intended for collection
2526

2627
def _iteration(self, engine, batchdata):
2728
engine.state.output = "called"

tests/test_image_filter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939

4040
class TestModule(torch.nn.Module):
41+
__test__ = False # indicate to pytest that this class is not intended for collection
4142

4243
def __init__(self):
4344
super().__init__()

tests/test_prepare_batch_default.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222

2323
class TestNet(torch.nn.Module):
24+
__test__ = False # indicate to pytest that this class is not intended for collection
2425

2526
def forward(self, x: torch.Tensor):
2627
return x

tests/test_prepare_batch_default_dist.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444

4545
class TestNet(torch.nn.Module):
46+
__test__ = False # indicate to pytest that this class is not intended for collection
4647

4748
def forward(self, x: torch.Tensor):
4849
return x

tests/test_prepare_batch_extra_input.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737

3838
class TestNet(torch.nn.Module):
39+
__test__ = False # indicate to pytest that this class is not intended for collection
3940

4041
def forward(self, x: torch.Tensor, t1=None, t2=None, t3=None):
4142
return {"x": x, "t1": t1, "t2": t2, "t3": t3}

0 commit comments

Comments
 (0)