-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Unit tests migration to pytest #778
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
Conversation
I agree, that test is a bit silly. 🔪
|
Looks good! thanks @Batalex |
tests/unit/development/__init__.py
Outdated
assert val1 == exp1 | ||
|
||
|
||
def assert_docstring(docstring): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Batalex this is a direct conversion from the original test right? I don't like the check line by line, it looks long and error-prone with the long list of strings.
Can we just check the hash of the content ? like hashlib.md5(string).hexdigest(), the hardcode part will be a simple digest string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@byronz If you are okay with that, I replaced those functions with difflib
. I think the hash approch is much harder to debug and equivalently error-prone.
Hardcoding the digest string would indeed be more concise, but we would not have any way of knowing why two hashes are different and this would require an extra step every time the docstring template is changed.
Even if we keep the hard coded docstring and compute the hash at runtime, the difficulty to figure out why the hashes are different remains
I also changed some other utils functions, all assert
are back in the tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Batalex I'm sorry for the late reply, I was on vacation last week. what's the difference of using the difflib vs pytest's own diff mechanism? did you find it more readable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries !
The main advantage of using difflib instead of what we had before is that we can now detect multiple errors in one test run. The previous version would fail a test on the first different line regardless of the total number of lines changed whereas here we get a git-like diff with all changes
78500ff
to
bec9cbc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💃 @Batalex thanks for the contribution.
As a continuation of #774, here is a PR migrating the remaining unitests to pytest:
I do need some inputs however on:
tests.unit.development.test_base_component.TestGenerateClass#test_call_signature
. It has the following comment above: "# This one is kind of pointless now". Should I transform it to pytest anyway?tests.unit.development.test_base_component.TestComponent#test_to_plotly_json_with_nested_children
does not seem to test anything, the assertion is enclosed in triple quotes. What should I do with it?Contributor Checklist
(edit by ACJ - removed unneeded steps. Thanks!)