Skip to content

Commit 6915c82

Browse files
pb8odianpopa
authored andcommitted
Add microvm factory fixture to aid testing
Signed-off-by: Pablo Barbáchano <[email protected]>
1 parent 0c734b6 commit 6915c82

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/conftest.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,29 @@ def microvm(test_fc_session_root_path, bin_cloner_path):
413413
shutil.rmtree(os.path.join(test_fc_session_root_path, vm.id))
414414

415415

416+
@pytest.fixture()
417+
def microvm_factory(tmp_path, bin_cloner_path):
418+
"""Fixture to create microvms simply.
419+
420+
By using tmp_path, the last 3 runs are kept. This may be a problem when
421+
running large number of tests, but it's very handy for debugging.
422+
"""
423+
424+
class MicroVMFactory:
425+
"""MicroVM factory"""
426+
427+
def __init__(self, tmp_path, bin_cloner):
428+
self.tmp_path = tmp_path
429+
self.bin_cloner_path = bin_cloner
430+
431+
def build(self):
432+
"""Build a fresh microvm."""
433+
vm = init_microvm(self.tmp_path, self.bin_cloner_path)
434+
return vm
435+
436+
yield MicroVMFactory(tmp_path, bin_cloner_path)
437+
438+
416439
@pytest.fixture
417440
def network_config():
418441
"""Yield a UniqueIPv4Generator."""

0 commit comments

Comments
 (0)