Skip to content

Commit

Permalink
test: move conftest.py to top-level, to cover tests/ also (canonical#414
Browse files Browse the repository at this point in the history
)

* 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.)

* 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.
OddBloke authored Jun 8, 2020
1 parent 4e534a7 commit 87b8080
Showing 3 changed files with 7 additions and 2 deletions.
File renamed without changes.
8 changes: 6 additions & 2 deletions tests/unittests/test_datasource/test_opennebula.py
Original file line number Diff line number Diff line change
@@ -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):
1 change: 1 addition & 0 deletions tests/unittests/test_render_cloudcfg.py
Original file line number Diff line number Diff line change
@@ -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')]

0 comments on commit 87b8080

Please sign in to comment.