-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Extend pytest.approx to handle strings. #3482
Comments
GitMate.io thinks possibly related issues are #3085 (Remove support for strings to pytest.main), #719 (pytest.mark.parametrize string-based parameter list doesn't handle single element tuples), #109 (Unable to extend reports when using pytest-xdist), #1411 (Pytest stops), and #544 (pytest 2.6 remove some strings in pathname). |
i propose using a new name for comp arables that support string matching, as its strictly a different topic |
If I understand correctly, we make a new class that is for comparing objects. Leaving approx alone so it can focus on numbers. Should this new |
this should be a plugin as a starting point as its not clear how to name things and how it should work |
I agree on using a different name than One pattern that I've used in the past is something like this: assert text == pytest.text_diff(expected, diff_lines=[25, 26, 78]) Where OTOH I've not used the approach anymore because it is hard to maintain the text along the code (specially large texts) so lately I have been using an approach similar to pytest-regtest. |
again - this should start outside of pytest, and have much more room for experimentation |
Im fine with starting it as a plugin and going from there. |
huumm... interesting, do you know if someone already started to create this plugin? |
At least I am unaware |
I think I will try to develop a plugin like that. It does not seem to be that difficult, let's see |
@marcelotrevisani cool, let me know if you have any questions. Also please update this issue if you end up publishing the plugin. 👍 |
I think we have a consensus that this should at least start as a plugin. Can close this? |
This issue is a developer and community discussion on how strings should be handled in pytest.approx()
Two of the easiest ways to do text matching in pytest are:
assert "abc" in "abcdef"
I enjoy the benefits that using
assert
gives me because of its strength in pytest, but It's not as flexible as Regex could possibly be.A handy use case I could see is checking to see if an expected string is close to a "template"
psudo-code###
perhaps there is a bounds of some sort
It seems that a template/bounds combo seems to be a good way to extend string comparison beyond the
substring in string
model.I am very eager to think about other ideas or use cases people have 😄
The text was updated successfully, but these errors were encountered: