Skip to content

Commit

Permalink
Cleanup warnings when collecting tests (#7914)
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 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 <hans-johnson@uiowa.edu>
Co-authored-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
  • Loading branch information
hjmjohnson and ericspod authored Jul 24, 2024
1 parent 316934a commit 12d00ce
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions monai/data/test_time_augmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ 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,
transform: InvertibleTransform,
Expand Down
1 change: 1 addition & 0 deletions tests/test_arraydataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +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_)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_auto3dseg.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ 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 @@ -132,6 +134,8 @@ 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
super().__init__(stats_name, report_format)
Expand All @@ -149,6 +153,8 @@ 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
report_format = {"test_stats": None}
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
1 change: 1 addition & 0 deletions tests/test_handler_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +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"
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
1 change: 1 addition & 0 deletions tests/test_prepare_batch_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +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 12d00ce

Please sign in to comment.