tests: gpt: Remove test order dependency

Re-create a clean disk image for each test to prevent modifications from
one test affecting another

Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
This commit is contained in:
Joshua Watt 2023-08-31 10:51:36 -06:00 committed by Tom Rini
parent d8d1fd0e89
commit a3eb350649

View file

@ -61,18 +61,14 @@ class GptTestDiskImage(object):
cmd = ('cp', persistent, self.path)
u_boot_utils.run_and_log(u_boot_console, cmd)
gtdi = None
@pytest.fixture(scope='function')
def state_disk_image(u_boot_console):
"""pytest fixture to provide a GptTestDiskImage object to tests.
This is function-scoped because it uses u_boot_console, which is also
function-scoped. However, we don't need to actually do any function-scope
work, so this simply returns the same object over and over each time."""
function-scoped. A new disk is returned each time to prevent tests from
interfering with each other."""
global gtdi
if not gtdi:
gtdi = GptTestDiskImage(u_boot_console)
return gtdi
return GptTestDiskImage(u_boot_console)
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('cmd_gpt')
@ -186,12 +182,12 @@ def test_gpt_swap_partitions(state_disk_image, u_boot_console):
u_boot_console.run_command('host bind 0 ' + state_disk_image.path)
output = u_boot_console.run_command('part list host 0')
assert '0x00000800 0x00000fff "first"' in output
assert '0x00001000 0x00001bff "second"' in output
u_boot_console.run_command('gpt swap host 0 first second')
assert '0x00000800 0x00000fff "part1"' in output
assert '0x00001000 0x00001bff "part2"' in output
u_boot_console.run_command('gpt swap host 0 part1 part2')
output = u_boot_console.run_command('part list host 0')
assert '0x00000800 0x00000fff "second"' in output
assert '0x00001000 0x00001bff "first"' in output
assert '0x00000800 0x00000fff "part2"' in output
assert '0x00001000 0x00001bff "part1"' in output
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('cmd_gpt')