From 8db89458b68993e83351f1ca9097609c94703ebb Mon Sep 17 00:00:00 2001 From: Kevin Hunter Kesling Date: Tue, 12 Nov 2024 23:33:37 -0500 Subject: [PATCH] Remove unnecessary warnings (#1718) Ensure deprecation is always warned, and simultaneously remove some unnecessary test output clutter. --- compute_endpoint/tests/conftest.py | 13 +++++++++++++ .../high_throughput/test_htex_regression.py | 2 +- .../tests/unit/test_bad_endpoint_config.py | 4 ++-- compute_endpoint/tests/unit/test_htex.py | 14 +++++--------- compute_endpoint/tests/unit/test_htex_facade.py | 2 +- 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/compute_endpoint/tests/conftest.py b/compute_endpoint/tests/conftest.py index 17dc144f8..11bacbd9f 100644 --- a/compute_endpoint/tests/conftest.py +++ b/compute_endpoint/tests/conftest.py @@ -224,3 +224,16 @@ def _pack_it(fn, *a, **k) -> bytes: ) return _pack_it + + +@pytest.fixture +def htex_warns(): + with pytest.warns(DeprecationWarning) as pyt_w: + yield + + def _warned(msg: str) -> bool: + test = "HighThroughputEngine is deprecated" in msg + test &= "Please use GlobusComputeEngine instead" in msg + return test + + assert any(_warned(str(w)) for w in pyt_w.list) diff --git a/compute_endpoint/tests/integration/endpoint/executors/high_throughput/test_htex_regression.py b/compute_endpoint/tests/integration/endpoint/executors/high_throughput/test_htex_regression.py index 1c7a8823f..5f5c3cfc2 100644 --- a/compute_endpoint/tests/integration/endpoint/executors/high_throughput/test_htex_regression.py +++ b/compute_endpoint/tests/integration/endpoint/executors/high_throughput/test_htex_regression.py @@ -9,7 +9,7 @@ @pytest.fixture -def engine(tmp_path): +def engine(tmp_path, htex_warns): ep_id = uuid.uuid4() engine = HighThroughputEngine( label="HTEXEngine", diff --git a/compute_endpoint/tests/unit/test_bad_endpoint_config.py b/compute_endpoint/tests/unit/test_bad_endpoint_config.py index 4789e9b42..ae73bcce6 100644 --- a/compute_endpoint/tests/unit/test_bad_endpoint_config.py +++ b/compute_endpoint/tests/unit/test_bad_endpoint_config.py @@ -7,7 +7,7 @@ @pytest.mark.parametrize("address", ("localhost", "login1.theta.alcf.anl.gov", "*")) -def test_invalid_address(address): +def test_invalid_address(address, htex_warns): with mock.patch(f"{_MOCK_BASE}log") as mock_log: with pytest.raises(ValueError): HighThroughputEngine(address=address) @@ -17,5 +17,5 @@ def test_invalid_address(address): @pytest.mark.parametrize( "address", ("192.168.64.12", "fe80::e643:4bff:fe61:8f72", "129.114.44.12") ) -def test_valid_address(address): +def test_valid_address(address, htex_warns): HighThroughputEngine(address=address) diff --git a/compute_endpoint/tests/unit/test_htex.py b/compute_endpoint/tests/unit/test_htex.py index 4b8a68bc9..e57b9a72e 100644 --- a/compute_endpoint/tests/unit/test_htex.py +++ b/compute_endpoint/tests/unit/test_htex.py @@ -16,6 +16,11 @@ from tests.utils import double, ez_pack_function, try_assert +@pytest.fixture(autouse=True) +def warning_invoked(htex_warns): + yield + + @pytest.fixture def htex(tmp_path): ep_id = uuid.uuid4() @@ -99,12 +104,3 @@ def test_engine_invalid_result_data(task_id: t.Optional[str]): htex.is_alive = False htex._engine_bad_state.set() queue_mgmt_thread.join() - - -def test_deprecation_notice(mocker): - mock_warn = mocker.patch( - "globus_compute_endpoint.engines.high_throughput.engine.warnings" - ) - HighThroughputEngine() - assert mock_warn.warn.called - assert "HighThroughputEngine is deprecated" in mock_warn.warn.call_args[0][0] diff --git a/compute_endpoint/tests/unit/test_htex_facade.py b/compute_endpoint/tests/unit/test_htex_facade.py index d68c7e583..725f44ea1 100644 --- a/compute_endpoint/tests/unit/test_htex_facade.py +++ b/compute_endpoint/tests/unit/test_htex_facade.py @@ -15,7 +15,7 @@ def test_deprecation_notice(mocker): assert "deprecated" in mock_warn.warn.call_args[0][0] -def test_htex_returns_engine(): +def test_htex_returns_engine(htex_warns): """An instance of HighThroughputExecutor should now return a HighThroughputEngine object """