Support assert statements inside validators#653
Support assert statements inside validators#653samuelcolvin merged 13 commits intopydantic:masterfrom abdusco:assert_statement_support
Conversation
Codecov Report
@@ Coverage Diff @@
## master #653 +/- ##
==========================================
- Coverage 100% 99.92% -0.08%
==========================================
Files 15 15
Lines 2720 2725 +5
Branches 534 536 +2
==========================================
+ Hits 2720 2723 +3
- Misses 0 2 +2 |
|
Please create an issue to discuss this first. Such big changes can't just be implemented directly as a PR. |
|
Ah sorry, good idea :) |
tiangolo
left a comment
There was a problem hiding this comment.
I like this! 🎉
I would suggest adding a section in the docs explaining how to use it and adding a small caveat about @dmontagu 's comment: #654 (comment)
|
@tiangolo Updated docs with a warning |
|
Away from my computer, so ignore this if it's covered in the code. If pytest is giving you trouble, add a simple python test like the mypy external tests and add it to make. |
samuelcolvin
left a comment
There was a problem hiding this comment.
LGTM, but please add a section to HISTORY.rst and also add a raw python test called perhaps tests/assert_test.py that tests an assert statement passing and failing and adding it to the make tests recipe.
|
any chance we could get this fixed? I would like to get everything currently pending on the next release so I can work exclusively on v1. |
|
This is missed release v0.32, let's now include it in v1. That wasn't my original plan, but probably makes sense since it's quite a big conceptual change (even if it's backwards compatible). |
|
please can you rebase and move the history change to |
|
I think I've addressed the outstanding issues in https://github.com/dmontagu/pydantic/tree/assert_statement_support I opened a PR against @abdusco 's branch (though it involved a rebase against master which I guess might cause issues). @samuelcolvin let me know if you want me to just make a separate PR. |
| fail_test(test_name, ['ValidationError was not raised']) | ||
|
|
||
|
|
||
| def fail_test(test_name: str, description: List[str]): |
There was a problem hiding this comment.
I added a little bit of pretty error reporting to make it easier for contributors to realize what is going wrong if this test is failing. @samuelcolvin Let me know if you take any issue with the style here.
|
Just realized I never pushed the fixes to the |
Change Summary
This PR adds support for
assertstatements inside validators (related: #654). This means we can use:to raise validation errors.
I've updated docs, but haven't been able to build it on Windows. I'm getting this error:
Checklist
HISTORY.rsthas been updated#<number>@<whomever>