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

Add insert_pytest_raises() #131

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

zmievsa
Copy link

@zmievsa zmievsa commented Jul 9, 2023

Every time I used insert_assert I was ecstatic with my new productivity but something was missing: it was always painful to catch and match exceptions. Only recently have I realized that same tooling and approach could be used to solve that problem as well.

Note that this is only a working prototype without tests or proper structure/naming.

If you like the idea -- I'll be happy to provide the rest :)

@codecov
Copy link

codecov bot commented Jul 9, 2023

Codecov Report

Merging #131 (0a8ac24) into main (1172e81) will increase coverage by 0.85%.
Report is 8 commits behind head on main.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #131      +/-   ##
==========================================
+ Coverage   96.27%   97.12%   +0.85%     
==========================================
  Files           8        8              
  Lines         725      766      +41     
  Branches      110      121      +11     
==========================================
+ Hits          698      744      +46     
+ Misses         21       17       -4     
+ Partials        6        5       -1     
Files Changed Coverage Δ
devtools/pytest_plugin.py 92.52% <100.00%> (+4.38%) ⬆️

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1172e81...0a8ac24. Read the comment docs.

Copy link
Owner

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks so much for the PR. I think I like it, please could you explain exactly how it works?

@zmievsa
Copy link
Author

zmievsa commented Aug 17, 2023

@samuelcolvin

The mechanism is exactly the same as in insert_assert, except that it's a context manager that catches the error and then replaces itself with a pytest.raises that captures the main error details. re.escape is used because pytest.raises checks using regexes by default so we avoid "invalid regex" errors using re.escape. I have been using it ever since I made this pull request and loved every second of it: it amazingly complements insert_assert. I'd like to write sections on it and on insert_assert in README/docs of this repo as I think that more people should know about these tools. But let's do it in a separate PR.

Demonstration

Before running the test:
image
After running the test:
image

I am not a huge fan of my naming but I can't come up with a better name for this function.
I am happy that you like the idea. I'll write the tests and comments now so that it's closer to being ready to be merged.

Update

Added tests. Mostly just copying the insert_assert tests

@zmievsa zmievsa marked this pull request as ready for review August 17, 2023 16:22
@zmievsa
Copy link
Author

zmievsa commented Sep 3, 2023

@samuelcolvin A gentle reminder to review this feature whenever you have a minute

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants