Skip to content

Commit e4c5520

Browse files
authored
Merge pull request #1377 from gcmoreira/pytest_image_autoselection_improvement
Testing: Enable automatic OS image selection by matching test name and image filename prefixes
2 parents fbc72d3 + 535ce3a commit e4c5520

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

.github/workflows/test.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ jobs:
2525
2626
- name: Download images
2727
run: |
28+
mkdir test_images
29+
cd test_images
2830
curl -sLO "https://downloads.volatilityfoundation.org/volatility3/images/linux-sample-1.bin.gz"
2931
gunzip linux-sample-1.bin.gz
3032
curl -sLO "https://downloads.volatilityfoundation.org/volatility3/images/win-xp-laptop-2005-06-25.img.gz"
3133
gunzip win-xp-laptop-2005-06-25.img.gz
34+
cd -
3235
3336
- name: Download and Extract symbols
3437
run: |
@@ -39,13 +42,12 @@ jobs:
3942
4043
- name: Testing...
4144
run: |
42-
pytest ./test/test_volatility.py --volatility=vol.py --image win-xp-laptop-2005-06-25.img -k test_windows -v
43-
pytest ./test/test_volatility.py --volatility=vol.py --image linux-sample-1.bin -k test_linux -v
45+
pytest ./test/test_volatility.py --volatility=vol.py --image-dir=./test_images -k test_windows -v
46+
pytest ./test/test_volatility.py --volatility=vol.py --image-dir=./test_images -k test_linux -v
4447
4548
- name: Clean up post-test
4649
run: |
47-
rm -rf *.bin
48-
rm -rf *.img
50+
rm -rf test_images
4951
cd volatility3/symbols
5052
rm -rf linux
5153
rm -rf linux.zip

test/conftest.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,39 @@ def pytest_addoption(parser):
3535
def pytest_generate_tests(metafunc):
3636
"""Parameterize tests based on image names"""
3737

38-
images = metafunc.config.getoption("image")
38+
images = metafunc.config.getoption("image").copy()
3939
for image_dir in metafunc.config.getoption("image_dir"):
40-
images = images + [
41-
os.path.join(image_dir, dir) for dir in os.listdir(image_dir)
40+
images += [
41+
os.path.join(image_dir, dir_name) for dir_name in os.listdir(image_dir)
4242
]
4343

44-
# tests with "image" parameter are run against images
44+
# tests with "image" parameter are run against image
4545
if "image" in metafunc.fixturenames:
46+
filtered_images = []
47+
ids = []
48+
for image in images:
49+
image_base = os.path.basename(image)
50+
test_name = metafunc.definition.originalname
51+
if test_name.startswith("test_windows_") and not image_base.startswith(
52+
"win-"
53+
):
54+
continue
55+
elif test_name.startswith("test_linux_") and not image_base.startswith(
56+
"linux-"
57+
):
58+
continue
59+
elif test_name.startswith("test_mac_") and not image_base.startswith(
60+
"mac-"
61+
):
62+
continue
63+
64+
filtered_images.append(image)
65+
ids.append(image_base)
66+
4667
metafunc.parametrize(
47-
"image", images, ids=[os.path.basename(image) for image in images]
68+
"image",
69+
filtered_images,
70+
ids=ids,
4871
)
4972

5073

0 commit comments

Comments
 (0)