-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: syrupy-project/syrupy#535. Move to pytest-snapshot since that is the only snapshot library that supports xdist. Update snapshot reporter plugin to work with pytest-snapshot.
- Loading branch information
1 parent
ddbc0f4
commit 6c20113
Showing
46 changed files
with
120 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,3 +53,6 @@ profile = black | |
|
||
[pep8] | ||
max-line-length = 150 | ||
|
||
[tool:pytest] | ||
addopts = -n auto |
Binary file removed
BIN
-341 Bytes
tests/__snapshots__/hud_test/test_hud_navigation[enter-network].png
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,78 @@ | ||
import pickle | ||
|
||
import pytest | ||
from imgcat import imgcat | ||
|
||
|
||
@pytest.hookimpl(trylast=True) | ||
def pytest_terminal_summary(terminalreporter, exitstatus, config) -> 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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Oops, something went wrong.