diff --git a/anta/runner.py b/anta/runner.py index 9fa536fa3..52aabcb21 100644 --- a/anta/runner.py +++ b/anta/runner.py @@ -31,7 +31,7 @@ DEFAULT_NOFILE = 16384 - @deprecated("This function is deprecated and will be removed in ANTA v2.0.0.") + @deprecated("This function is deprecated and will be removed in ANTA v2.0.0. Use AntaRunner class instead.", category=DeprecationWarning) def adjust_rlimit_nofile() -> tuple[int, int]: """Adjust the maximum number of open file descriptors for the ANTA process. @@ -61,6 +61,7 @@ def adjust_rlimit_nofile() -> tuple[int, int]: logger = logging.getLogger(__name__) +@deprecated("This function is deprecated and will be removed in ANTA v2.0.0. Use AntaRunner class instead.", category=DeprecationWarning) def log_cache_statistics(devices: list[AntaDevice]) -> None: """Log cache statistics for each device in the inventory. @@ -81,6 +82,7 @@ def log_cache_statistics(devices: list[AntaDevice]) -> None: logger.info("Caching is not enabled on %s", device.name) +@deprecated("This function is deprecated and will be removed in ANTA v2.0.0. Use AntaRunner class instead.", category=DeprecationWarning) async def setup_inventory(inventory: AntaInventory, tags: set[str] | None, devices: set[str] | None, *, established_only: bool) -> AntaInventory | None: """Set up the inventory for the ANTA run. @@ -123,6 +125,7 @@ async def setup_inventory(inventory: AntaInventory, tags: set[str] | None, devic return selected_inventory +@deprecated("This function is deprecated and will be removed in ANTA v2.0.0. Use AntaRunner class instead.", category=DeprecationWarning) def prepare_tests( inventory: AntaInventory, catalog: AntaCatalog, tests: set[str] | None, tags: set[str] | None ) -> defaultdict[AntaDevice, set[AntaTestDefinition]] | None: @@ -179,6 +182,7 @@ def prepare_tests( return device_to_tests +@deprecated("This function is deprecated and will be removed in ANTA v2.0.0. Use AntaRunner class instead.", category=DeprecationWarning) def get_coroutines(selected_tests: defaultdict[AntaDevice, set[AntaTestDefinition]], manager: ResultManager | None = None) -> list[Coroutine[Any, Any, TestResult]]: """Get the coroutines for the ANTA run. diff --git a/tests/benchmark/test_anta.py b/tests/benchmark/test_anta.py index 1daf7f369..346ebfd89 100644 --- a/tests/benchmark/test_anta.py +++ b/tests/benchmark/test_anta.py @@ -37,6 +37,7 @@ def test_anta_dry_run( results = session_results[request.node.callspec.id] + # TODO: Use AntaRunner in ANTA v2.0.0 @benchmark def _() -> None: results.reset() @@ -69,6 +70,7 @@ def test_anta( results = session_results[request.node.callspec.id] + # TODO: Use AntaRunner in ANTA v2.0.0 @benchmark def _() -> None: results.reset() diff --git a/tests/benchmark/test_runner.py b/tests/benchmark/test_runner.py index a2fa9ac27..6879c19f5 100644 --- a/tests/benchmark/test_runner.py +++ b/tests/benchmark/test_runner.py @@ -7,6 +7,8 @@ from typing import TYPE_CHECKING, Any +import pytest + from anta._runner import AntaRunner, AntaRunnerScope from anta.result_manager import ResultManager from anta.runner import get_coroutines, prepare_tests @@ -23,6 +25,8 @@ from anta.result_manager.models import TestResult +# TODO: Remove this in ANTA v2.0.0 +@pytest.mark.filterwarnings("ignore::DeprecationWarning") def test_prepare_tests(benchmark: BenchmarkFixture, catalog: AntaCatalog, inventory: AntaInventory) -> None: """Benchmark `anta.runner.prepare_tests`.""" @@ -37,6 +41,8 @@ def _() -> defaultdict[AntaDevice, set[AntaTestDefinition]] | None: assert sum(len(tests) for tests in selected_tests.values()) == len(inventory) * len(catalog.tests) +# TODO: Remove this in ANTA v2.0.0 +@pytest.mark.filterwarnings("ignore::DeprecationWarning") def test_get_coroutines(benchmark: BenchmarkFixture, catalog: AntaCatalog, inventory: AntaInventory) -> None: """Benchmark `anta.runner.get_coroutines`.""" selected_tests = prepare_tests(inventory=inventory, catalog=catalog, tests=None, tags=None) diff --git a/tests/units/test_runner.py b/tests/units/test_runner.py index e547c9546..d96fce17e 100644 --- a/tests/units/test_runner.py +++ b/tests/units/test_runner.py @@ -30,7 +30,7 @@ FAKE_CATALOG: AntaCatalog = AntaCatalog.from_list([(FakeTest, None)]) -# TODO: Move this to TestAntaRunner in ANTA v2.0.0 +# TODO: Move this to AntaRunner tests in ANTA v2.0.0 async def test_empty_tests(caplog: pytest.LogCaptureFixture, inventory: AntaInventory) -> None: """Test that when the list of tests is empty, a log is raised.""" caplog.set_level(logging.INFO) @@ -50,7 +50,7 @@ async def test_empty_tests(caplog: pytest.LogCaptureFixture, inventory: AntaInve assert "The list of tests is empty, exiting" in caplog.records[record_index].message -# TODO: Move this to TestAntaRunner in ANTA v2.0.0 +# TODO: Move this to AntaRunner tests in ANTA v2.0.0 async def test_empty_inventory(caplog: pytest.LogCaptureFixture) -> None: """Test that when the Inventory is empty, a log is raised.""" caplog.set_level(logging.INFO) @@ -70,7 +70,7 @@ async def test_empty_inventory(caplog: pytest.LogCaptureFixture) -> None: assert "The inventory is empty, exiting" in caplog.records[record_index].message -# TODO: Move this to TestAntaRunner in ANTA v2.0.0 +# TODO: Move this to AntaRunner tests in ANTA v2.0.0 @pytest.mark.parametrize( ("inventory", "tags", "devices"), [ @@ -94,6 +94,7 @@ async def test_no_selected_device(caplog: pytest.LogCaptureFixture, inventory: A # TODO: Remove this in ANTA v2.0.0 +@pytest.mark.filterwarnings("ignore::DeprecationWarning") @pytest.mark.skipif(os.name != "posix", reason="Cannot run this test on Windows") def test_adjust_rlimit_nofile_valid_env(caplog: pytest.LogCaptureFixture) -> None: """Test adjust_rlimit_nofile with valid environment variables.""" @@ -128,6 +129,7 @@ def side_effect_setrlimit(resource_id: int, limits: tuple[int, int]) -> None: # TODO: Remove this in ANTA v2.0.0 +@pytest.mark.filterwarnings("ignore::DeprecationWarning") @pytest.mark.skipif(os.name != "posix", reason="Cannot run this test on Windows") def test_adjust_rlimit_nofile_invalid_env(caplog: pytest.LogCaptureFixture) -> None: """Test adjust_rlimit_nofile with valid environment variables.""" @@ -162,7 +164,7 @@ def side_effect_setrlimit(resource_id: int, limits: tuple[int, int]) -> None: setrlimit_mock.assert_called_once_with(resource.RLIMIT_NOFILE, (16384, 1048576)) -# TODO: Move this to TestAntaRunner in ANTA v2.0.0 +# TODO: Move this to AntaRunner tests in ANTA v2.0.0 @pytest.mark.skipif(os.name == "posix", reason="Run this test on Windows only") async def test_check_runner_log_for_windows(caplog: pytest.LogCaptureFixture, inventory: AntaInventory) -> None: """Test log output for Windows host regarding rlimit.""" @@ -173,7 +175,7 @@ async def test_check_runner_log_for_windows(caplog: pytest.LogCaptureFixture, in assert "Running on a non-POSIX system, cannot adjust the maximum number of file descriptors." in caplog.records[0].message -# TODO: Move this to TestAntaRunner in ANTA v2.0.0 +# TODO: Move this to AntaRunner tests in ANTA v2.0.0 # We could instead merge multiple coverage report together but that requires more work than just this. @pytest.mark.skipif(os.name != "posix", reason="Fake non-posix for coverage") async def test_check_runner_log_for_windows_fake(caplog: pytest.LogCaptureFixture, inventory: AntaInventory) -> None: @@ -189,6 +191,7 @@ async def test_check_runner_log_for_windows_fake(caplog: pytest.LogCaptureFixtur assert "Running on a non-POSIX system, cannot adjust the maximum number of file descriptors." in caplog.records[0].message +@pytest.mark.filterwarnings("ignore::DeprecationWarning") @pytest.mark.parametrize( ("inventory", "tags", "tests", "devices_count", "tests_count"), [ @@ -218,7 +221,7 @@ async def test_prepare_tests( assert sum(len(tests) for tests in selected_tests.values()) == tests_count -# TODO: Remove this in ANTA v2.0.0 +# TODO: Move this to AntaRunner tests in ANTA v2.0.0 async def test_dry_run(caplog: pytest.LogCaptureFixture, inventory: AntaInventory) -> None: """Test that when dry_run is True, no tests are run.""" caplog.set_level(logging.INFO) @@ -227,7 +230,7 @@ async def test_dry_run(caplog: pytest.LogCaptureFixture, inventory: AntaInventor assert "Dry-run mode, exiting before running the tests." in caplog.records[-1].message -# TODO: Move this to TestAntaRunner in ANTA v2.0.0 +# TODO: Move this to AntaRunner tests in ANTA v2.0.0 async def test_cannot_create_test(caplog: pytest.LogCaptureFixture, inventory: AntaInventory) -> None: """Test that when an Exception is raised during test instantiation, it is caught and a log is raised.""" caplog.set_level(logging.CRITICAL)