diff options
author | Daniel Watkins <oddbloke@ubuntu.com> | 2020-07-02 13:51:28 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-02 11:51:28 -0600 |
commit | 2b727914e8cbee6810b1bb9a1cfdb90ad521ceb6 (patch) | |
tree | 41c2b91e3509da06cf6ed2c536b7e0032609209d /cloudinit/tests | |
parent | e31f7fe43aa8f352097c4bb3e97fc3acca8a26b7 (diff) | |
download | vyos-cloud-init-2b727914e8cbee6810b1bb9a1cfdb90ad521ceb6.tar.gz vyos-cloud-init-2b727914e8cbee6810b1bb9a1cfdb90ad521ceb6.zip |
tests: use markers to configure disable_subp_usage (#473)
This is an improvement over indirect parameterisation for a few reasons:
* The test code is much easier to read, the mark names are much more
intuitive than the indirect parameterisation invocation, and there's
less boilerplate to boot
* The fixture no longer has to overload the single parameter that
fixtures can take with multiple meanings
Diffstat (limited to 'cloudinit/tests')
-rw-r--r-- | cloudinit/tests/test_conftest.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/cloudinit/tests/test_conftest.py b/cloudinit/tests/test_conftest.py index a6537248..6f1263a5 100644 --- a/cloudinit/tests/test_conftest.py +++ b/cloudinit/tests/test_conftest.py @@ -17,12 +17,11 @@ class TestDisableSubpUsage: # pylint: disable=no-value-for-parameter subp.subp() - @pytest.mark.parametrize('disable_subp_usage', [False], indirect=True) + @pytest.mark.allow_all_subp def test_subp_usage_can_be_reenabled(self): subp.subp(['whoami']) - @pytest.mark.parametrize( - 'disable_subp_usage', [['whoami'], 'whoami'], indirect=True) + @pytest.mark.allow_subp_for("whoami") def test_subp_usage_can_be_conditionally_reenabled(self): # The two parameters test each potential invocation with a single # argument @@ -31,8 +30,7 @@ class TestDisableSubpUsage: assert "allowed: whoami" in str(excinfo.value) subp.subp(['whoami']) - @pytest.mark.parametrize( - 'disable_subp_usage', [['whoami', 'bash']], indirect=True) + @pytest.mark.allow_subp_for("whoami", "bash") def test_subp_usage_can_be_conditionally_reenabled_for_multiple_cmds(self): with pytest.raises(AssertionError) as excinfo: subp.subp(["some", "args"]) @@ -40,6 +38,12 @@ class TestDisableSubpUsage: subp.subp(['bash', '-c', 'true']) subp.subp(['whoami']) + @pytest.mark.allow_all_subp + @pytest.mark.allow_subp_for("bash") + def test_both_marks_raise_an_error(self): + with pytest.raises(AssertionError, match="marked both"): + subp.subp(["bash"]) + class TestDisableSubpUsageInTestSubclass(CiTestCase): """Test that disable_subp_usage doesn't impact CiTestCase's subp logic.""" |