Skip to content

Commit

Permalink
tests: fix PytestRemovedIn8Warning ("support for nose tests is deprec…
Browse files Browse the repository at this point in the history
…ated and will be removed in a future release")

Before this change, the test log contained 37 entries like this:
    PytestRemovedIn8Warning: Support for nose tests is deprecated and will be removed in a future release.

After this change, on my machine the test log shrinks from 1672 to 1405 lines
(16% less).

At some point in time, we will migrate to Pytest 8.x, and this would be an
hindrance.

A reference for the fix can be found at:
    https://docs.pytest.org/en/stable/deprecations.html#support-for-tests-written-for-nose

Affected tests were found with:
    rg "def (setup|teardown)\(" tests
  • Loading branch information
muxator authored and muxator committed Sep 13, 2024
1 parent c5f8eb7 commit 55e65fe
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion tests/test_calibrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class TestCalibrate:
],
)

def setup(self) -> None:
def setup_method(self) -> None:
"""Set up the tests."""
self.true_params = np.array([0.50, 0.50])
self.bounds = [
Expand Down
2 changes: 1 addition & 1 deletion tests/test_losses/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def compute_loss_1d(
sim_data: NDArray[np.float64]
real_data: NDArray[np.float64]

def setup(self) -> None:
def setup_method(self) -> None:
"""Set up the tests."""
self.loss = TestComputeLoss.MyCustomLoss(
self.loss_constant,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_plot/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ class BasePlotResultsTest(BasePlotTest):
saving_folder: Path

@classmethod
def setup(cls) -> None:
def setup_method(cls) -> None:
"""Set up the test."""
cls.args = [cls.saving_folder, *cls.args]
2 changes: 1 addition & 1 deletion tests/test_plot/test_plot_descriptive_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class TestTsStats(BasePlotTest):
args: Sequence[Any] = ()
expected_image = PLOT_DIR / "ts_stats-expected.png"

def setup(self) -> None:
def setup_method(self) -> None:
"""Set up the test."""
rng = np.random.default_rng(42)
data = rng.random(100)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_plot/test_plot_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_run_by_method_num(self, method_num: int) -> None:
self.args = [self.saving_folder, method_num]
super().run()

def teardown(self) -> None:
def teardown_method(self) -> None:
"""Tear down the test."""
# restore default attributes
delattr(self, "expected_image")
Expand Down Expand Up @@ -113,7 +113,7 @@ def test_run_by_batch_num(self, batch_num: int) -> None:
self.args = [self.saving_folder, list(range(batch_num))]
super().run()

def teardown(self) -> None:
def teardown_method(self) -> None:
"""Tear down the test."""
# restore default attributes
delattr(self, "expected_image")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_samplers/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def sample_batch(
"""Sample a batch of parameters."""
return self.random_generator.random(size=(batch_size, search_space.dims))

def setup(self) -> None:
def setup_method(self) -> None:
"""Set up the tests."""
self.bounds = [[0.10, 0.10, 0.10], [1.00, 1.00, 1.00]]
self.bounds_step = [0.01, 0.01, 0.01]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_samplers/test_gaussian_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
class TestGaussianProcess2D:
"""Test GaussianProcess sampling."""

def setup(self) -> None:
def setup_method(self) -> None:
"""Set up the test."""
self.xys, self.losses = self._construct_fake_grid(seed=0)

Expand Down

0 comments on commit 55e65fe

Please sign in to comment.