From 6c20113de7066bed88fd50a87ebf757e4d86d558 Mon Sep 17 00:00:00 2001 From: olivierwilkinson Date: Wed, 9 Mar 2022 11:22:18 +0000 Subject: [PATCH] test: fix performance issues when all tests run Use pytest-xdist plugin to run the tests concurrently in different processes. Splitting the execution across multiple workers significantly reduces the time to run the tests. Syrupy does not support xdist: https://github.com/tophat/syrupy/issues/535. Move to pytest-snapshot since that is the only snapshot library that supports xdist. Update snapshot reporter plugin to work with pytest-snapshot. --- conftest.py | 8 +- setup.cfg | 3 + .../test_hud_navigation[enter-network].png | Bin 341 -> 0 bytes tests/hud_test.py | 24 ++--- tests/network_test.py | 24 ++--- tests/overview_test.py | 20 ++-- tests/plugins/snapshot_reporter.py | 86 ++++++++++++++---- tests/requirements.txt | 3 +- .../test_hud_navigation/enter-network.png} | Bin .../test_hud_navigation/enter-settings.png} | Bin .../test_hud_navigation/enter-system.png} | Bin .../test_hud_navigation/leave-network.png} | Bin .../test_hud_navigation/leave-settings.png} | Bin .../test_hud_navigation/leave-system.png} | Bin .../hud_test/test_hud_navigation/network.png} | Bin .../test_hud_navigation/overview.png} | Bin .../test_hud_navigation/scroll-up.png} | Bin .../test_hud_navigation/settings.png} | Bin .../hud_test/test_hud_navigation/system.png} | Bin .../network_test/test_ap/connected.png} | Bin .../network_test/test_ap/disconnected.png} | Bin .../network_test/test_ethernet/connected.png} | Bin .../test_ethernet/disconnected.png} | Bin .../network_test/test_usb/connected.png} | Bin .../network_test/test_usb/disconnected.png} | Bin .../network_test/test_wifi/connected.png} | Bin .../network_test/test_wifi/disconnected.png | Bin 0 -> 361 bytes .../capacity-change.png} | Bin .../test_overview_battery/charging.png} | Bin .../test_overview_battery/discharging.png} | Bin .../test_overview_battery/full.png} | Bin .../test_overview_network/ethernet.png} | Bin .../test_overview_network/localhost.png} | Bin .../test_overview_network/usb.png} | Bin .../test_overview_network/wifi.png} | Bin .../test_battery/capacity-change.png} | Bin .../system_test/test_battery/charging.png} | Bin .../system_test/test_battery/discharging.png} | Bin .../system_test/test_battery/full.png} | Bin .../system_test/test_cpu/default.png} | Bin .../system_test/test_cpu/levels-change.png} | Bin .../system_test/test_login/custom.png} | Bin .../system_test/test_login/default.png} | Bin .../system_test/test_memory/default.png} | Bin .../test_memory/memory-change.png} | Bin tests/system_test.py | 28 +++--- 46 files changed, 120 insertions(+), 76 deletions(-) delete mode 100644 tests/__snapshots__/hud_test/test_hud_navigation[enter-network].png rename tests/{__snapshots__/network_test/test_wifi[disconnected].png => snapshots/hud_test/test_hud_navigation/enter-network.png} (100%) rename tests/{__snapshots__/hud_test/test_hud_navigation[enter-settings].png => snapshots/hud_test/test_hud_navigation/enter-settings.png} (100%) rename tests/{__snapshots__/hud_test/test_hud_navigation[enter-system].png => snapshots/hud_test/test_hud_navigation/enter-system.png} (100%) rename tests/{__snapshots__/hud_test/test_hud_navigation[leave-network].png => snapshots/hud_test/test_hud_navigation/leave-network.png} (100%) rename tests/{__snapshots__/hud_test/test_hud_navigation[leave-settings].png => snapshots/hud_test/test_hud_navigation/leave-settings.png} (100%) rename tests/{__snapshots__/hud_test/test_hud_navigation[leave-system].png => snapshots/hud_test/test_hud_navigation/leave-system.png} (100%) rename tests/{__snapshots__/hud_test/test_hud_navigation[network].png => snapshots/hud_test/test_hud_navigation/network.png} (100%) rename tests/{__snapshots__/hud_test/test_hud_navigation[overview].png => snapshots/hud_test/test_hud_navigation/overview.png} (100%) rename tests/{__snapshots__/hud_test/test_hud_navigation[scroll-up].png => snapshots/hud_test/test_hud_navigation/scroll-up.png} (100%) rename tests/{__snapshots__/hud_test/test_hud_navigation[settings].png => snapshots/hud_test/test_hud_navigation/settings.png} (100%) rename tests/{__snapshots__/hud_test/test_hud_navigation[system].png => snapshots/hud_test/test_hud_navigation/system.png} (100%) rename tests/{__snapshots__/network_test/test_ap[connected].png => snapshots/network_test/test_ap/connected.png} (100%) rename tests/{__snapshots__/network_test/test_ap[disconnected].png => snapshots/network_test/test_ap/disconnected.png} (100%) rename tests/{__snapshots__/network_test/test_ethernet[connected].png => snapshots/network_test/test_ethernet/connected.png} (100%) rename tests/{__snapshots__/network_test/test_ethernet[disconnected].png => snapshots/network_test/test_ethernet/disconnected.png} (100%) rename tests/{__snapshots__/network_test/test_usb[connected].png => snapshots/network_test/test_usb/connected.png} (100%) rename tests/{__snapshots__/network_test/test_usb[disconnected].png => snapshots/network_test/test_usb/disconnected.png} (100%) rename tests/{__snapshots__/network_test/test_wifi[connected].png => snapshots/network_test/test_wifi/connected.png} (100%) create mode 100644 tests/snapshots/network_test/test_wifi/disconnected.png rename tests/{__snapshots__/overview_test/test_overview_battery[capacity-change].png => snapshots/overview_test/test_overview_battery/capacity-change.png} (100%) rename tests/{__snapshots__/overview_test/test_overview_battery[charging].png => snapshots/overview_test/test_overview_battery/charging.png} (100%) rename tests/{__snapshots__/overview_test/test_overview_battery[discharging].png => snapshots/overview_test/test_overview_battery/discharging.png} (100%) rename tests/{__snapshots__/overview_test/test_overview_battery[full].png => snapshots/overview_test/test_overview_battery/full.png} (100%) rename tests/{__snapshots__/overview_test/test_overview_network[ethernet].png => snapshots/overview_test/test_overview_network/ethernet.png} (100%) rename tests/{__snapshots__/overview_test/test_overview_network[localhost].png => snapshots/overview_test/test_overview_network/localhost.png} (100%) rename tests/{__snapshots__/overview_test/test_overview_network[usb].png => snapshots/overview_test/test_overview_network/usb.png} (100%) rename tests/{__snapshots__/overview_test/test_overview_network[wifi].png => snapshots/overview_test/test_overview_network/wifi.png} (100%) rename tests/{__snapshots__/system_test/test_battery[capacity-change].png => snapshots/system_test/test_battery/capacity-change.png} (100%) rename tests/{__snapshots__/system_test/test_battery[charging].png => snapshots/system_test/test_battery/charging.png} (100%) rename tests/{__snapshots__/system_test/test_battery[discharging].png => snapshots/system_test/test_battery/discharging.png} (100%) rename tests/{__snapshots__/system_test/test_battery[full].png => snapshots/system_test/test_battery/full.png} (100%) rename tests/{__snapshots__/system_test/test_cpu[default].png => snapshots/system_test/test_cpu/default.png} (100%) rename tests/{__snapshots__/system_test/test_cpu[levels-change].png => snapshots/system_test/test_cpu/levels-change.png} (100%) rename tests/{__snapshots__/system_test/test_login[custom].png => snapshots/system_test/test_login/custom.png} (100%) rename tests/{__snapshots__/system_test/test_login[default].png => snapshots/system_test/test_login/default.png} (100%) rename tests/{__snapshots__/system_test/test_memory[default].png => snapshots/system_test/test_memory/default.png} (100%) rename tests/{__snapshots__/system_test/test_memory[memory-change].png => snapshots/system_test/test_memory/memory-change.png} (100%) diff --git a/conftest.py b/conftest.py index b5cdb5f5..a463d23a 100644 --- a/conftest.py +++ b/conftest.py @@ -4,12 +4,11 @@ import pytest from PIL import ImageFont -from syrupy.extensions.image import PNGImageSnapshotExtension from pt_miniscreen.state import ScheduledAppEvent from pt_miniscreen.utils import get_image_file_path -pytest_plugins = ("syrupy", "tests.plugins.snapshot_reporter") +pytest_plugins = ("pytest_snapshot", "tests.plugins.snapshot_reporter") @pytest.fixture() @@ -70,8 +69,3 @@ def app(patch_packages, patch_font, patch_images): @pytest.fixture def miniscreen(app): yield app.miniscreen - - -@pytest.fixture -def image_snapshot(snapshot): - return snapshot.use_extension(PNGImageSnapshotExtension) diff --git a/setup.cfg b/setup.cfg index 856a1a1d..035d1136 100644 --- a/setup.cfg +++ b/setup.cfg @@ -53,3 +53,6 @@ profile = black [pep8] max-line-length = 150 + +[tool:pytest] +addopts = -n auto diff --git a/tests/__snapshots__/hud_test/test_hud_navigation[enter-network].png b/tests/__snapshots__/hud_test/test_hud_navigation[enter-network].png deleted file mode 100644 index 30a04a8e3dad9ade504cc0b0e44c92a4fb8ad011..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 341 zcmV-b0jmCqP)@K9f*2A`mh&{y!}HQoe47Cj3=1dlH0p%pY9 zGTClM=u&hp3E#}*|0fBc(Fh3{HoN`qZA1V7G5s157>2cv?WCe=oDvqhWx_6tnWw#^ z0#Q9D@KGWKb(~?CI@P?QY6Xzb96lOdhvHyb~K9m{~4GjLF None: - if exitstatus == 0: - return +def is_master(config): + return not hasattr(config, "workerinput") - terminalreporter.write_sep("-", "snapshot diff") - syrupy_report = terminalreporter.config._syrupy.report - for assertion in syrupy_report.assertions: - for execution in assertion.executions.values(): - if execution.success: - continue +def pytest_configure(config): + plugin = SnapshotReporter(config) + config.pluginmanager.register(plugin) - terminalreporter.write_line(execution.snapshot_location) - terminalreporter.write_line("Expected:") - if execution.recalled_data: - imgcat(execution.recalled_data) - else: - terminalreporter.write_line("None") +class SnapshotReporter: + def __init__(self, config): + self.config = config + self.is_master = is_master(config) + self.failed_snapshots = [] + + def track_snapshot(self, snapshot): + def track_assert(fn): + def tracked(value, snapshot_name): + try: + fn(value, snapshot_name) + except AssertionError as e: + path = snapshot._snapshot_path(snapshot_name) + self.failed_snapshots.append( + { + "path": str(path), + "received": value, + "expected": path.read_bytes() if path.is_file() else None, + } + ) + + raise e + + return tracked + + snapshot.assert_match = track_assert(snapshot.assert_match) + snapshot.assert_match_dir = track_assert(snapshot.assert_match_dir) + + @pytest.fixture + def snapshot(self, snapshot): + self.track_snapshot(snapshot) + yield snapshot + + @pytest.hookimpl(hookwrapper=True, trylast=True) + def pytest_sessionfinish(self, session, exitstatus): + yield + if not self.is_master: + self.config.workeroutput["failed_snapshots"] = pickle.dumps( + self.failed_snapshots + ) + + def pytest_testnodedown(self, node, error): + worker_snapshots = pickle.loads(node.workeroutput["failed_snapshots"]) + self.failed_snapshots.extend(worker_snapshots) + + @pytest.hookimpl(trylast=True) + def pytest_terminal_summary(self, terminalreporter, exitstatus): + if exitstatus == 0: + return + + terminalreporter.write_sep("=", "snapshot diff") + + for failed_snapshot in self.failed_snapshots: + terminalreporter.write_sep("-", failed_snapshot["path"]) terminalreporter.write_line("Received:") - if execution.asserted_data: - imgcat(execution.asserted_data) + imgcat(failed_snapshot["received"]) + + terminalreporter.write_line("Expected:") + if failed_snapshot["expected"]: + imgcat(failed_snapshot["expected"]) else: terminalreporter.write_line("None") - - terminalreporter.write_line("\n") diff --git a/tests/requirements.txt b/tests/requirements.txt index 8a0741e6..ec8d0abb 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,7 +1,8 @@ pytest pytest-cov pytest-mock -syrupy>=1.7.4 +pytest-xdist +pytest-snapshot>=0.8.1 Pillow>=8.1.2 imgcat>=0.5.0 psutil>=5.8.0 diff --git a/tests/__snapshots__/network_test/test_wifi[disconnected].png b/tests/snapshots/hud_test/test_hud_navigation/enter-network.png similarity index 100% rename from tests/__snapshots__/network_test/test_wifi[disconnected].png rename to tests/snapshots/hud_test/test_hud_navigation/enter-network.png diff --git a/tests/__snapshots__/hud_test/test_hud_navigation[enter-settings].png b/tests/snapshots/hud_test/test_hud_navigation/enter-settings.png similarity index 100% rename from tests/__snapshots__/hud_test/test_hud_navigation[enter-settings].png rename to tests/snapshots/hud_test/test_hud_navigation/enter-settings.png diff --git a/tests/__snapshots__/hud_test/test_hud_navigation[enter-system].png b/tests/snapshots/hud_test/test_hud_navigation/enter-system.png similarity index 100% rename from tests/__snapshots__/hud_test/test_hud_navigation[enter-system].png rename to tests/snapshots/hud_test/test_hud_navigation/enter-system.png diff --git a/tests/__snapshots__/hud_test/test_hud_navigation[leave-network].png b/tests/snapshots/hud_test/test_hud_navigation/leave-network.png similarity index 100% rename from tests/__snapshots__/hud_test/test_hud_navigation[leave-network].png rename to tests/snapshots/hud_test/test_hud_navigation/leave-network.png diff --git a/tests/__snapshots__/hud_test/test_hud_navigation[leave-settings].png b/tests/snapshots/hud_test/test_hud_navigation/leave-settings.png similarity index 100% rename from tests/__snapshots__/hud_test/test_hud_navigation[leave-settings].png rename to tests/snapshots/hud_test/test_hud_navigation/leave-settings.png diff --git a/tests/__snapshots__/hud_test/test_hud_navigation[leave-system].png b/tests/snapshots/hud_test/test_hud_navigation/leave-system.png similarity index 100% rename from tests/__snapshots__/hud_test/test_hud_navigation[leave-system].png rename to tests/snapshots/hud_test/test_hud_navigation/leave-system.png diff --git a/tests/__snapshots__/hud_test/test_hud_navigation[network].png b/tests/snapshots/hud_test/test_hud_navigation/network.png similarity index 100% rename from tests/__snapshots__/hud_test/test_hud_navigation[network].png rename to tests/snapshots/hud_test/test_hud_navigation/network.png diff --git a/tests/__snapshots__/hud_test/test_hud_navigation[overview].png b/tests/snapshots/hud_test/test_hud_navigation/overview.png similarity index 100% rename from tests/__snapshots__/hud_test/test_hud_navigation[overview].png rename to tests/snapshots/hud_test/test_hud_navigation/overview.png diff --git a/tests/__snapshots__/hud_test/test_hud_navigation[scroll-up].png b/tests/snapshots/hud_test/test_hud_navigation/scroll-up.png similarity index 100% rename from tests/__snapshots__/hud_test/test_hud_navigation[scroll-up].png rename to tests/snapshots/hud_test/test_hud_navigation/scroll-up.png diff --git a/tests/__snapshots__/hud_test/test_hud_navigation[settings].png b/tests/snapshots/hud_test/test_hud_navigation/settings.png similarity index 100% rename from tests/__snapshots__/hud_test/test_hud_navigation[settings].png rename to tests/snapshots/hud_test/test_hud_navigation/settings.png diff --git a/tests/__snapshots__/hud_test/test_hud_navigation[system].png b/tests/snapshots/hud_test/test_hud_navigation/system.png similarity index 100% rename from tests/__snapshots__/hud_test/test_hud_navigation[system].png rename to tests/snapshots/hud_test/test_hud_navigation/system.png diff --git a/tests/__snapshots__/network_test/test_ap[connected].png b/tests/snapshots/network_test/test_ap/connected.png similarity index 100% rename from tests/__snapshots__/network_test/test_ap[connected].png rename to tests/snapshots/network_test/test_ap/connected.png diff --git a/tests/__snapshots__/network_test/test_ap[disconnected].png b/tests/snapshots/network_test/test_ap/disconnected.png similarity index 100% rename from tests/__snapshots__/network_test/test_ap[disconnected].png rename to tests/snapshots/network_test/test_ap/disconnected.png diff --git a/tests/__snapshots__/network_test/test_ethernet[connected].png b/tests/snapshots/network_test/test_ethernet/connected.png similarity index 100% rename from tests/__snapshots__/network_test/test_ethernet[connected].png rename to tests/snapshots/network_test/test_ethernet/connected.png diff --git a/tests/__snapshots__/network_test/test_ethernet[disconnected].png b/tests/snapshots/network_test/test_ethernet/disconnected.png similarity index 100% rename from tests/__snapshots__/network_test/test_ethernet[disconnected].png rename to tests/snapshots/network_test/test_ethernet/disconnected.png diff --git a/tests/__snapshots__/network_test/test_usb[connected].png b/tests/snapshots/network_test/test_usb/connected.png similarity index 100% rename from tests/__snapshots__/network_test/test_usb[connected].png rename to tests/snapshots/network_test/test_usb/connected.png diff --git a/tests/__snapshots__/network_test/test_usb[disconnected].png b/tests/snapshots/network_test/test_usb/disconnected.png similarity index 100% rename from tests/__snapshots__/network_test/test_usb[disconnected].png rename to tests/snapshots/network_test/test_usb/disconnected.png diff --git a/tests/__snapshots__/network_test/test_wifi[connected].png b/tests/snapshots/network_test/test_wifi/connected.png similarity index 100% rename from tests/__snapshots__/network_test/test_wifi[connected].png rename to tests/snapshots/network_test/test_wifi/connected.png diff --git a/tests/snapshots/network_test/test_wifi/disconnected.png b/tests/snapshots/network_test/test_wifi/disconnected.png new file mode 100644 index 0000000000000000000000000000000000000000..ddd8bbb2d93f76ecc98e5adf055dc8b5c30e0219 GIT binary patch literal 361 zcmV-v0ha!WP)b?Q*DK@C$fPw8aa4WJ#fP8iVLe(O{Lka8t`;29vuX2!ZHZ`CSK1jHYoR&ZX zrD6lpLjXpitawYDmY3KF)MX3dFEwTa7GPB0j{uY!t6ZtE$|d~p9h{*}VCY(3yL3R9 z?n!`-sC*n(Kq8?ZbFzAL5k8!omTr`7wYG28_wNjNjdJD?KE(#Kb(#z#01pcC`&r7z z)ofR*NXvzU`R|u&1}ztKUEs$KFyCPTqM%9TdiqDF|MA#gmy%L9t{vB)00000NkvXX Hu0mjffe4vX literal 0 HcmV?d00001 diff --git a/tests/__snapshots__/overview_test/test_overview_battery[capacity-change].png b/tests/snapshots/overview_test/test_overview_battery/capacity-change.png similarity index 100% rename from tests/__snapshots__/overview_test/test_overview_battery[capacity-change].png rename to tests/snapshots/overview_test/test_overview_battery/capacity-change.png diff --git a/tests/__snapshots__/overview_test/test_overview_battery[charging].png b/tests/snapshots/overview_test/test_overview_battery/charging.png similarity index 100% rename from tests/__snapshots__/overview_test/test_overview_battery[charging].png rename to tests/snapshots/overview_test/test_overview_battery/charging.png diff --git a/tests/__snapshots__/overview_test/test_overview_battery[discharging].png b/tests/snapshots/overview_test/test_overview_battery/discharging.png similarity index 100% rename from tests/__snapshots__/overview_test/test_overview_battery[discharging].png rename to tests/snapshots/overview_test/test_overview_battery/discharging.png diff --git a/tests/__snapshots__/overview_test/test_overview_battery[full].png b/tests/snapshots/overview_test/test_overview_battery/full.png similarity index 100% rename from tests/__snapshots__/overview_test/test_overview_battery[full].png rename to tests/snapshots/overview_test/test_overview_battery/full.png diff --git a/tests/__snapshots__/overview_test/test_overview_network[ethernet].png b/tests/snapshots/overview_test/test_overview_network/ethernet.png similarity index 100% rename from tests/__snapshots__/overview_test/test_overview_network[ethernet].png rename to tests/snapshots/overview_test/test_overview_network/ethernet.png diff --git a/tests/__snapshots__/overview_test/test_overview_network[localhost].png b/tests/snapshots/overview_test/test_overview_network/localhost.png similarity index 100% rename from tests/__snapshots__/overview_test/test_overview_network[localhost].png rename to tests/snapshots/overview_test/test_overview_network/localhost.png diff --git a/tests/__snapshots__/overview_test/test_overview_network[usb].png b/tests/snapshots/overview_test/test_overview_network/usb.png similarity index 100% rename from tests/__snapshots__/overview_test/test_overview_network[usb].png rename to tests/snapshots/overview_test/test_overview_network/usb.png diff --git a/tests/__snapshots__/overview_test/test_overview_network[wifi].png b/tests/snapshots/overview_test/test_overview_network/wifi.png similarity index 100% rename from tests/__snapshots__/overview_test/test_overview_network[wifi].png rename to tests/snapshots/overview_test/test_overview_network/wifi.png diff --git a/tests/__snapshots__/system_test/test_battery[capacity-change].png b/tests/snapshots/system_test/test_battery/capacity-change.png similarity index 100% rename from tests/__snapshots__/system_test/test_battery[capacity-change].png rename to tests/snapshots/system_test/test_battery/capacity-change.png diff --git a/tests/__snapshots__/system_test/test_battery[charging].png b/tests/snapshots/system_test/test_battery/charging.png similarity index 100% rename from tests/__snapshots__/system_test/test_battery[charging].png rename to tests/snapshots/system_test/test_battery/charging.png diff --git a/tests/__snapshots__/system_test/test_battery[discharging].png b/tests/snapshots/system_test/test_battery/discharging.png similarity index 100% rename from tests/__snapshots__/system_test/test_battery[discharging].png rename to tests/snapshots/system_test/test_battery/discharging.png diff --git a/tests/__snapshots__/system_test/test_battery[full].png b/tests/snapshots/system_test/test_battery/full.png similarity index 100% rename from tests/__snapshots__/system_test/test_battery[full].png rename to tests/snapshots/system_test/test_battery/full.png diff --git a/tests/__snapshots__/system_test/test_cpu[default].png b/tests/snapshots/system_test/test_cpu/default.png similarity index 100% rename from tests/__snapshots__/system_test/test_cpu[default].png rename to tests/snapshots/system_test/test_cpu/default.png diff --git a/tests/__snapshots__/system_test/test_cpu[levels-change].png b/tests/snapshots/system_test/test_cpu/levels-change.png similarity index 100% rename from tests/__snapshots__/system_test/test_cpu[levels-change].png rename to tests/snapshots/system_test/test_cpu/levels-change.png diff --git a/tests/__snapshots__/system_test/test_login[custom].png b/tests/snapshots/system_test/test_login/custom.png similarity index 100% rename from tests/__snapshots__/system_test/test_login[custom].png rename to tests/snapshots/system_test/test_login/custom.png diff --git a/tests/__snapshots__/system_test/test_login[default].png b/tests/snapshots/system_test/test_login/default.png similarity index 100% rename from tests/__snapshots__/system_test/test_login[default].png rename to tests/snapshots/system_test/test_login/default.png diff --git a/tests/__snapshots__/system_test/test_memory[default].png b/tests/snapshots/system_test/test_memory/default.png similarity index 100% rename from tests/__snapshots__/system_test/test_memory[default].png rename to tests/snapshots/system_test/test_memory/default.png diff --git a/tests/__snapshots__/system_test/test_memory[memory-change].png b/tests/snapshots/system_test/test_memory/memory-change.png similarity index 100% rename from tests/__snapshots__/system_test/test_memory[memory-change].png rename to tests/snapshots/system_test/test_memory/memory-change.png diff --git a/tests/system_test.py b/tests/system_test.py index 21c189e8..ebd2060e 100644 --- a/tests/system_test.py +++ b/tests/system_test.py @@ -76,15 +76,15 @@ def setup(miniscreen, cpu_percent, user, memory): sleep(1) -def test_login(miniscreen, image_snapshot, user): - assert miniscreen.device.display_image == image_snapshot(name="default") +def test_login(miniscreen, snapshot, user): + snapshot.assert_match(miniscreen.device.display_image, "default.png") user("olivier", default_pass=False) sleep(1.5) - assert miniscreen.device.display_image == image_snapshot(name="custom") + snapshot.assert_match(miniscreen.device.display_image, "custom.png") -def test_battery(battery, miniscreen, image_snapshot): +def test_battery(battery, miniscreen, snapshot): # scroll to battery page miniscreen.down_button.release() sleep(1) @@ -92,42 +92,42 @@ def test_battery(battery, miniscreen, image_snapshot): battery.is_charging = True battery.when_charging() sleep(1) - assert miniscreen.device.display_image == image_snapshot(name="charging") + snapshot.assert_match(miniscreen.device.display_image, "charging.png") battery.is_full = True battery.capacity = 100 battery.when_full() sleep(1) - assert miniscreen.device.display_image == image_snapshot(name="full") + snapshot.assert_match(miniscreen.device.display_image, "full.png") battery.is_charging = False battery.is_full = False battery.capacity = 99 battery.when_discharging() sleep(1) - assert miniscreen.device.display_image == image_snapshot(name="discharging") + snapshot.assert_match(miniscreen.device.display_image, "discharging.png") battery.capacity = 98 battery.on_capacity_change(98) sleep(1) - assert miniscreen.device.display_image == image_snapshot(name="capacity-change") + snapshot.assert_match(miniscreen.device.display_image, "capacity-change.png") -def test_cpu(miniscreen, image_snapshot, cpu_percent): +def test_cpu(miniscreen, snapshot, cpu_percent): # scroll to cpu page miniscreen.down_button.release() sleep(1) miniscreen.down_button.release() sleep(1) - assert miniscreen.device.display_image == image_snapshot(name="default") + snapshot.assert_match(miniscreen.device.display_image, "default.png") cpu_percent([55.5, 30, 10, 100]) sleep(0.5) - assert miniscreen.device.display_image == image_snapshot(name="levels-change") + snapshot.assert_match(miniscreen.device.display_image, "levels-change.png") -def test_memory(miniscreen, image_snapshot, memory): +def test_memory(miniscreen, snapshot, memory): # scroll to memory page miniscreen.down_button.release() sleep(1) @@ -136,8 +136,8 @@ def test_memory(miniscreen, image_snapshot, memory): miniscreen.down_button.release() sleep(1) - assert miniscreen.device.display_image == image_snapshot(name="default") + snapshot.assert_match(miniscreen.device.display_image, "default.png") memory(virtual=999, swap=127.9876655) sleep(1.5) - assert miniscreen.device.display_image == image_snapshot(name="memory-change") + snapshot.assert_match(miniscreen.device.display_image, "memory-change.png")