From 516cee35b0a1296f1173cf96a3cff3a1cfcf369c Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Mon, 18 May 2020 17:30:40 -0400 Subject: [PATCH 1/2] test_opennebula: convert TestParseShellConfig to a pytest test And allow it to run bash. (We aren't aiming to convert TestCase tests to pytest tests as a rule. In this case, I needed to change its implementation to limit subp usage, and I chose pytest over CiTestCase.) --- tests/unittests/test_datasource/test_opennebula.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/unittests/test_datasource/test_opennebula.py b/tests/unittests/test_datasource/test_opennebula.py index de896a9ec66..7c859c8af17 100644 --- a/tests/unittests/test_datasource/test_opennebula.py +++ b/tests/unittests/test_datasource/test_opennebula.py @@ -9,6 +9,8 @@ import pwd import unittest +import pytest + TEST_VARS = { 'VAR1': 'single', @@ -914,12 +916,14 @@ def test_multiple_nics(self): self.assertEqual(expected, net.gen_conf()) -class TestParseShellConfig(unittest.TestCase): +class TestParseShellConfig: + + @pytest.mark.parametrize('disable_subp_usage', ['bash'], indirect=True) def test_no_seconds(self): cfg = '\n'.join(["foo=bar", "SECONDS=2", "xx=foo"]) # we could test 'sleep 2', but that would make the test run slower. ret = ds.parse_shell_config(cfg) - self.assertEqual(ret, {"foo": "bar", "xx": "foo"}) + assert ret == {"foo": "bar", "xx": "foo"} def populate_context_dir(path, variables): From 358a034de7fd63b063a1d983c5f7479aca7f2630 Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Mon, 18 May 2020 17:33:10 -0400 Subject: [PATCH 2/2] test: move conftest.py to top-level, to cover tests/ also This gives us a single conftest.py which is shared by all tests in the project. --- cloudinit/conftest.py => conftest.py | 0 tests/unittests/test_render_cloudcfg.py | 1 + 2 files changed, 1 insertion(+) rename cloudinit/conftest.py => conftest.py (100%) diff --git a/cloudinit/conftest.py b/conftest.py similarity index 100% rename from cloudinit/conftest.py rename to conftest.py diff --git a/tests/unittests/test_render_cloudcfg.py b/tests/unittests/test_render_cloudcfg.py index 393a78b16e5..696915a37bb 100644 --- a/tests/unittests/test_render_cloudcfg.py +++ b/tests/unittests/test_render_cloudcfg.py @@ -13,6 +13,7 @@ "netbsd", "openbsd", "rhel", "suse", "ubuntu", "unknown"] +@pytest.mark.parametrize('disable_subp_usage', [sys.executable], indirect=True) class TestRenderCloudCfg: cmd = [sys.executable, os.path.realpath('tools/render-cloudcfg')]