From 27e87979283bab68ba64aeb50fd7d2562ac33a0d Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Wed, 4 Feb 2026 13:04:49 +0100 Subject: [PATCH] Ensure inventory tests are cleaned up At the moment `tox -e inventory` may leave leftovers, which does affect consecutive runs. This is quite annoying, and also may result in extra files in tree to be added to commit accidentally. Change-Id: If7bde86e2770cc2e018376c745e4f3b8bf24dcf8 Signed-off-by: Dmitriy Rabotyagov --- .gitignore | 1 + tests/inventory/.gitkeep | 1 - tests/test_inventory.py | 6 ++++-- tox.ini | 9 ++++++++- 4 files changed, 13 insertions(+), 4 deletions(-) delete mode 100644 tests/inventory/.gitkeep diff --git a/.gitignore b/.gitignore index 83da161dff..b0d94a0aca 100644 --- a/.gitignore +++ b/.gitignore @@ -70,6 +70,7 @@ releasenotes/build playbooks/root-include-playbook.yml playbooks/include-playbook.yml* playbooks/logs +tests/inventory # ignore zanata/sphinx cache on translation job .zanata-cache/ diff --git a/tests/inventory/.gitkeep b/tests/inventory/.gitkeep deleted file mode 100644 index cb93c0fa9c..0000000000 --- a/tests/inventory/.gitkeep +++ /dev/null @@ -1 +0,0 @@ -Keep this file to keep the directory. diff --git a/tests/test_inventory.py b/tests/test_inventory.py index 4be9a18609..b0a4177bf8 100644 --- a/tests/test_inventory.py +++ b/tests/test_inventory.py @@ -69,6 +69,7 @@ def make_config(): # Allow access here so we can populate the dictionary. global _BASE_CONFIG + os.makedirs(TARGET_DIR, exist_ok=True) _BASE_CONFIG = tools.make_example_config(AIO_CONFIG_FILE, CONFD) tools.write_example_config(USER_CONFIG_FILE, _BASE_CONFIG) @@ -83,6 +84,7 @@ def tearDownModule(): # This file should only be removed after all tests are run, # thus it is excluded from cleanup. os.remove(USER_CONFIG_FILE) + os.rmdir(TARGET_DIR) def cleanup(): @@ -1350,7 +1352,7 @@ class TestLxcHosts(TestConfigCheckBase): inventory = get_inventory() # insert compute1 into lxc_hosts, which mimicks bug behavior inventory['lxc_hosts']['hosts'].append('compute1') - faked_path = INV_DIR + faked_path = TARGET_DIR with mock.patch('osa_toolkit.filesystem.load_inventory') as inv_mock: inv_mock.return_value = (inventory, faked_path) @@ -1367,7 +1369,7 @@ class TestLxcHosts(TestConfigCheckBase): self.assertNotIn('lxc_hosts', inventory.keys()) - faked_path = INV_DIR + faked_path = TARGET_DIR with mock.patch('osa_toolkit.filesystem.load_inventory') as inv_mock: inv_mock.return_value = (inventory, faked_path) new_inventory = get_inventory() diff --git a/tox.ini b/tox.ini index af4ad0b14c..d2697ab4af 100644 --- a/tox.ini +++ b/tox.ini @@ -93,6 +93,9 @@ deps = -r{toxinidir}/global-requirement-pins.txt [testenv:inventory] +allowlist_externals = + {[testenv]allowlist_externals} + rm # Use a fixed seed since some inventory tests rely on specific ordering deps = {[testenv]deps} @@ -103,8 +106,10 @@ install_command = pip install {opts} {packages} setenv = {[testenv]setenv} PYTHONHASHSEED = 100 -commands = +commands_pre = + rm -rf {toxinidir}/tests/inventory coverage erase +commands = coverage run -a {toxinidir}/tests/test_inventory.py coverage run -a {toxinidir}/tests/test_manage.py coverage run -a {toxinidir}/tests/test_dictutils.py @@ -112,6 +117,8 @@ commands = coverage run -a {toxinidir}/tests/test_filesystem.py coverage run -a {toxinidir}/tests/test_releases.py coverage report --show-missing --include={toxinidir}/inventory/*,{toxinidir}/osa_toolkit/* +commands_post = + rm -rf {toxinidir}/tests/inventory [testenv:py3-inventory] setenv =