From 95f078a845a0e0ff9ecea98304ffa573bd59e548 Mon Sep 17 00:00:00 2001 From: Nicholas Wiltsie Date: Tue, 18 Jun 2024 16:00:20 -0700 Subject: [PATCH 1/4] Show non-determinism --- test/unit/test_NFTestAssert.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/unit/test_NFTestAssert.py b/test/unit/test_NFTestAssert.py index badb614..018ed04 100644 --- a/test/unit/test_NFTestAssert.py +++ b/test/unit/test_NFTestAssert.py @@ -12,6 +12,9 @@ @mock.patch("nftest.NFTestAssert.NFTestAssert", wraps=NFTestAssert) def test_get_assert_method_value_error(mock_assert): """Tests value error from get_assert_method when given `method` is not supported""" + # Make an NFTestAssert object + NFTestAssert("", "") + assert_method = "nomethod" mock_assert.return_value.script = None mock_assert.return_value.method = assert_method From c3a3a971af2d5118841068eaf3adfb13fb2a2875 Mon Sep 17 00:00:00 2001 From: Nicholas Wiltsie Date: Tue, 18 Jun 2024 16:14:42 -0700 Subject: [PATCH 2/4] Remove non-determinism from test --- test/unit/test_NFTestEnv.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/unit/test_NFTestEnv.py b/test/unit/test_NFTestEnv.py index 433fc79..61fdcd6 100644 --- a/test/unit/test_NFTestEnv.py +++ b/test/unit/test_NFTestEnv.py @@ -17,8 +17,12 @@ def test_nftest_env_load(monkeypatch): monkeypatch.setenv("NFT_LOG_LEVEL", test_log_level) monkeypatch.setenv("NFT_LOG", test_log_file) + # Clear any existing singleton value + NFTestENV._instances.pop(NFTestENV, None) nftest_env = NFTestENV() + assert NFTestENV in NFTestENV._instances + assert nftest_env.NFT_OUTPUT == test_out_directory assert nftest_env.NFT_TEMP == test_temp_directory assert nftest_env.NFT_INIT == test_init_directory @@ -32,3 +36,8 @@ def test_singleton(): nftest_env2 = NFTestENV() assert id(nftest_env1) == id(nftest_env2) + + NFTestENV._instances.pop(NFTestENV, None) + nftest_env3 = NFTestENV() + + assert id(nftest_env1) != id(nftest_env3) From 82d604def811b717d5303fc2bb5d7691a6fbc307 Mon Sep 17 00:00:00 2001 From: Nicholas Wiltsie Date: Tue, 18 Jun 2024 16:15:19 -0700 Subject: [PATCH 3/4] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e6186b..73cbfe9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Fixed - Make `nftest` with no arguments print usage and exit +- Resolve non-determinism in NFTestENV unit tests --- From 0d05f30c0a5f7a8addf34284b37da60924ef72d9 Mon Sep 17 00:00:00 2001 From: Nicholas Wiltsie Date: Tue, 18 Jun 2024 16:32:15 -0700 Subject: [PATCH 4/4] Silence warnings about my short-term fixes --- test/unit/test_NFTestEnv.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/unit/test_NFTestEnv.py b/test/unit/test_NFTestEnv.py index 61fdcd6..c37d299 100644 --- a/test/unit/test_NFTestEnv.py +++ b/test/unit/test_NFTestEnv.py @@ -18,10 +18,10 @@ def test_nftest_env_load(monkeypatch): monkeypatch.setenv("NFT_LOG", test_log_file) # Clear any existing singleton value - NFTestENV._instances.pop(NFTestENV, None) + NFTestENV._instances.pop(NFTestENV, None) # pylint: disable=protected-access nftest_env = NFTestENV() - assert NFTestENV in NFTestENV._instances + assert NFTestENV in NFTestENV._instances # pylint: disable=protected-access assert nftest_env.NFT_OUTPUT == test_out_directory assert nftest_env.NFT_TEMP == test_temp_directory @@ -37,7 +37,7 @@ def test_singleton(): assert id(nftest_env1) == id(nftest_env2) - NFTestENV._instances.pop(NFTestENV, None) + NFTestENV._instances.pop(NFTestENV, None) # pylint: disable=protected-access nftest_env3 = NFTestENV() assert id(nftest_env1) != id(nftest_env3)