Skip to content

Commit

Permalink
User errro
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenvp committed Jan 31, 2024
1 parent 65b2ae6 commit 51ecb42
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
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"

0 comments on commit 51ecb42

Please sign in to comment.