Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User errro #20

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ of every change, see the Git log.

Latest
------
* tbd
* Minor: Added access to the user_error on the exception object

1.5.0
-----
Expand Down
3 changes: 3 additions & 0 deletions src/pytest_datarecorder/datarecorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ def __init__(
if user_error:
result += f"{user_error}\n"

# Make sure we can ass only the user error if we want
self.user_error = user_error

super(DataRecorderError, self).__init__(result)


Expand Down
15 changes: 15 additions & 0 deletions test/test_datarecorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,23 @@ def on_mismatch(mismatch_data, recording_data, mismatch_dir, mismatch_context):
mismatch_context="scatter",
)

assert e.user_error is True

assert "Data mismatch at index [0, 3]" in str(e.value)
assert mismatch_index == [0, 3]

# Check that the mismatch directory contains the files
assert mismatch_dir.contains_file("scatter.json")

def on_mismatch(mismatch_data, recording_data, mismatch_dir, mismatch_context):
return "Data mismatch"

with pytest.raises(pytest_datarecorder.datarecorder.DataRecorderError) as e:
datarecorder.record_data(
data=[5, 2, 3, 1, 5],
recording_file=recording_file,
mismatch_callback=on_mismatch,
mismatch_dir=mismatch_dir.path(),
)

assert e.user_error == "Data mismatch"
Loading