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

Unit tests migration to pytest #778

Merged
merged 16 commits into from
Jul 9, 2019
Merged

Conversation

Batalex
Copy link
Contributor

@Batalex Batalex commented Jun 18, 2019

As a continuation of #774, here is a PR migrating the remaining unitests to pytest:

  • The behavior of each test should not have been changed, I just used pytest shortcuts for some of them.
  • I kept classes where I thought it was a nice scope delimiter

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

  • I have broken down my PR scope into the following TODO tasks
    • Migrate units tests to pytest
  • I have run the tests locally and they passed. (refer to testing section in contributing)

(edit by ACJ - removed unneeded steps. Thanks!)

tests/unit/test_configs.py Outdated Show resolved Hide resolved
@alexcjohnson
Copy link
Collaborator

  • 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?

I agree, that test is a bit silly. 🔪

  • 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?

LOL it's been that way for 2 years
Screen Shot 2019-06-18 at 9 35 19 AM
🔪

@byronz
Copy link
Contributor

byronz commented Jun 18, 2019

Looks good! thanks @Batalex

@Batalex Batalex changed the title WIP: Unit tests migration to pytest Unit tests migration to pytest Jun 19, 2019
assert val1 == exp1


def assert_docstring(docstring):
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

@byronz byronz left a 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.

@byronz byronz merged commit 9b24dee into plotly:master Jul 9, 2019
@Batalex Batalex deleted the tests/pytest-migration branch July 24, 2019 15:29
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

3 participants