Skip to content

Commit

Permalink
Cleanup warnings when collecting tests
Browse files Browse the repository at this point in the history
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 supress attempted collection in those
non test-classes

Signed-off-by: Hans Johnson <hans-johnson@uiowa.edu>
  • Loading branch information
hjmjohnson committed Jul 12, 2024
1 parent 14b086b commit d926f2b
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions monai/data/test_time_augmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class TestTimeAugmentation:
)
mode, mean, std, vvc = tt_aug(test_data)
"""
__test__ = False # indicate to pytest that this class is not intended for collection

def __init__(
self,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_arraydataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@


class TestCompose(Compose):

__test__ = False # indicate to pytest that this class is not intended for collection
def __call__(self, input_, lazy=False):
img = self.transforms[0](input_)
metadata = img.meta
Expand Down
3 changes: 3 additions & 0 deletions tests/test_auto3dseg.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class TestOperations(Operations):
"""
Test example for user operation
"""
__test__ = False # indicate to pytest that this class is not intended for collection

def __init__(self) -> None:
self.data = {"max": np.max, "mean": np.mean, "min": np.min}
Expand All @@ -131,6 +132,7 @@ class TestAnalyzer(Analyzer):
"""
Test example for a simple Analyzer
"""
__test__ = False # indicate to pytest that this class is not intended for collection

def __init__(self, key, report_format, stats_name="test"):
self.key = key
Expand All @@ -148,6 +150,7 @@ class TestImageAnalyzer(Analyzer):
"""
Test example for a simple Analyzer
"""
__test__ = False # indicate to pytest that this class is not intended for collection

def __init__(self, image_key="image", stats_name="test_image"):
self.image_key = image_key
Expand Down
1 change: 1 addition & 0 deletions tests/test_convert_data_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@


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


Expand Down
2 changes: 2 additions & 0 deletions tests/test_handler_prob_map_producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@


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

def __init__(self, name, size):
super().__init__(
Expand Down Expand Up @@ -64,6 +65,7 @@ def __getitem__(self, index):


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

def _iteration(self, engine, batchdata):
return batchdata
Expand Down
2 changes: 1 addition & 1 deletion tests/test_handler_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


class TestEvaluator(Evaluator):

__test__ = False # indicate to pytest that this class is not intended for collection
def _iteration(self, engine, batchdata):
engine.state.output = "called"
return engine.state.output
Expand Down
1 change: 1 addition & 0 deletions tests/test_image_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@


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

def __init__(self):
super().__init__()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_prepare_batch_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


class TestNet(torch.nn.Module):

__test__ = False # indicate to pytest that this class is not intended for collection
def forward(self, x: torch.Tensor):
return x

Expand Down
1 change: 1 addition & 0 deletions tests/test_prepare_batch_default_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@


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

def forward(self, x: torch.Tensor):
return x
Expand Down
1 change: 1 addition & 0 deletions tests/test_prepare_batch_extra_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@


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

def forward(self, x: torch.Tensor, t1=None, t2=None, t3=None):
return {"x": x, "t1": t1, "t2": t2, "t3": t3}
Expand Down
1 change: 1 addition & 0 deletions tests/test_prepare_batch_hovernet.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@


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

def forward(self, x: torch.Tensor):
return {HoVerNetBranch.NP: torch.tensor([1, 2]), HoVerNetBranch.NC: torch.tensor([4, 4]), HoVerNetBranch.HV: 16}
Expand Down
1 change: 1 addition & 0 deletions tests/test_torchscript_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@


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

def forward(self, x):
return x + 10
Expand Down

0 comments on commit d926f2b

Please sign in to comment.