diff options
author | James Falcon <james.falcon@canonical.com> | 2021-11-22 16:56:41 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-22 16:56:41 -0600 |
commit | 31daf6670aeeba1d452c70bc0d4d04139652be36 (patch) | |
tree | e892ab1389fdcd36c77ea985711b09e5d113dcdb /conftest.py | |
parent | 1343584dc03c50c80eabb8199c4e7d0d6fb4bd56 (diff) | |
download | vyos-cloud-init-31daf6670aeeba1d452c70bc0d4d04139652be36.tar.gz vyos-cloud-init-31daf6670aeeba1d452c70bc0d4d04139652be36.zip |
testing: monkeypatch system_info call in unit tests (SC-533) (#1117)
testing: monkeypatch system_info call in unit tests
system_info can make calls that read or write from the filesystem, which
should require special mocking. It is also decorated with 'lru_cache',
which means test authors often don't realize they need to be mocking.
Also, we don't actually want the results from the user's local
machine, so monkeypatching it across all tests should be reasonable.
Additionally, moved some of 'system_info` into a helper function to
reduce the surface area of the monkeypatch, added tests for the new
function (and fixed a bug as a result), and removed related mocks that
should be no longer needed.
Diffstat (limited to 'conftest.py')
-rw-r--r-- | conftest.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/conftest.py b/conftest.py index 9e9d9ff8..f3f8c036 100644 --- a/conftest.py +++ b/conftest.py @@ -12,7 +12,7 @@ from unittest import mock import pytest -from cloudinit import helpers, subp +from cloudinit import helpers, subp, util class _FixtureUtils: @@ -201,3 +201,19 @@ def paths(tmpdir): "run_dir": tmpdir.mkdir("run_dir").strpath, } return helpers.Paths(dirs) + + +@pytest.fixture(autouse=True, scope='session') +def monkeypatch_system_info(): + def my_system_info(): + return { + "platform": "invalid", + "system": "invalid", + "release": "invalid", + "python": "invalid", + "uname": ["invalid"] * 6, + "dist": ("Distro", "-1.1", "Codename"), + "variant": "ubuntu" + } + + util.system_info = my_system_info |