Skip to content

Instantly share code, notes, and snippets.

@abadger
Created March 14, 2023 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abadger/238eca60f1664e4fbf91f6285d54f6a5 to your computer and use it in GitHub Desktop.
Save abadger/238eca60f1664e4fbf91f6285d54f6a5 to your computer and use it in GitHub Desktop.
How to write a unittest fixture
diff --git a/convert2rhel/unit_tests/actions/actions_test.py b/convert2rhel/unit_tests/actions/actions_test.py
index 8dbac8a..0716164 100644
--- a/convert2rhel/unit_tests/actions/actions_test.py
+++ b/convert2rhel/unit_tests/actions/actions_test.py
@@ -584,6 +584,9 @@ def _gen_version(major, minor):
class TestEFIChecks(unittest.TestCase):
+ def setUp(self):
+ self.efi_check = actions.efi_check.EfiCheck()
+
def _check_efi_detection_log(self, efi_detected=True):
if efi_detected:
self.assertNotIn("BIOS detected.", actions.logger.info_msgs)
@@ -666,7 +669,7 @@ class TestEFIChecks(unittest.TestCase):
@unit_tests.mock(os.path, "exists", lambda x: x == "/usr/sbin/efibootmgr")
@unit_tests.mock(grub, "EFIBootInfo", EFIBootInfoMocked(current_bootnum="0002"))
def test_check_efi_efi_detected_nofile_entry(self):
- actions.check_efi()
+ self.efi_check()
self._check_efi_detection_log()
warn_msg = (
"The current UEFI bootloader '0002' is not referring to any binary UEFI file located on local"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment