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

Doctest report format option (#1749) #1754

Merged
merged 12 commits into from
Jul 23, 2016

Conversation

hartym
Copy link
Contributor

@hartym hartym commented Jul 23, 2016

Here is a first pull request, as it is my first contribution, I may have done incorrect things according to pytest standards, please let me know whatever I should do more or differently.

  • Target: for bug or doc fixes, target master; for new features, target features
  • Make sure to include one or more tests for your change
  • Add yourself to AUTHORS
  • Add a new entry to the CHANGELOG (choose any open position to avoid merge conflicts with other PRs)

@coveralls
Copy link

coveralls commented Jul 23, 2016

Coverage Status

Coverage increased (+0.04%) to 93.08% when pulling 87ca4b9 on hartym:1749_doctest_report_format into ae07985 on pytest-dev:features.

@@ -70,6 +70,9 @@ time or change existing behaviors in order to make them less surprising/more use
namespace in which doctests run.
Thanks `@milliams`_ for the complete PR (`#1428`_).

* New ``--doctest-report`` option available to change the output format of diffs
Copy link
Member

Choose a reason for hiding this comment

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

Nit pick: "when displaying failed doctests (#1749). Thanks @hartym for the PR." 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does that mean I should thank myself in the changelog? also removed the ticket reference, as it was making lint fail.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, sounds weird but we like to have people acknowledged in the CHANGELOG. A maintainer could do it before/after merging, but then we couldn't just use GitHub's merge button so we ask people to prepare the final CHANGELOG message so we can speed things up. 😁

About the missing link, you just have to add the proper link reference... scroll down in the CHANGELOG and you will see a long list of links. Just add your link there and linting should now work.

)
)

def _get_report_choices_keys():
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick here: wouldn't be simpler to just have _get_report_choices() and use _get_report_choices().keys() when you need the keys instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was the first implementation, but then it required to import doctest at the option parsing time, and it was making test suite fail (because i guess some doctest dependency is importing logging, and there's a test that checks it is not the case.)

See discussion at #1749 (and first impl at 625b603 that broke the tests). Let me know if you want me to change back but then I have no idea how to avoid this import related failure.

Copy link
Member

Choose a reason for hiding this comment

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

Oh I see. OK that makes sense, thanks!

Could you add a little explanation to get_report_choices_keys() like "return report choices keys. separate function because this is used to declare options and we can't import doctest at that time"? Just so the next person who stumbles on this doesn't wonder the same thing. 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In ec7695e

@coveralls
Copy link

coveralls commented Jul 23, 2016

Coverage Status

Coverage increased (+0.04%) to 93.08% when pulling 014ebc9 on hartym:1749_doctest_report_format into ae07985 on pytest-dev:features.

' 2 3 6',
])

def test_doctest_report_none_or_only_first_failure(self, testdir):
Copy link
Member

Choose a reason for hiding this comment

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

I suggest using parametrize here as well:

@pytest.mark.parametrize('format', ['none', 'only_first_failure'])
def test_doctest_report_none_or_only_first_failure(self, testdir, format):

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In e229a27

Copy link
Member

Choose a reason for hiding this comment

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

e229a27 was about test_doctest_report_udiff correct? I mean here that you can avoid the inner loop and use parametrize in here as well:

@pytest.mark.parametrize('format', ['none', 'only_first_failure'])
def test_doctest_report_none_or_only_first_failure(self, testdir):    
    result = self._run_doctest_report(testdir, format)
    result.stdout.fnmatch_lines([
        'Expected:',
        '       a  b',
        '    0  1  4',
        '    1  2  4',
        '    2  3  6',
        'Got:',
        '       a  b',
        '    0  1  4',
        '    1  2  5',
        '    2  3  6',
    ])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad, kind of applied dumbly your comment, did not remember about this other loop.

@coveralls
Copy link

coveralls commented Jul 23, 2016

Coverage Status

Coverage increased (+0.02%) to 93.057% when pulling e229a27 on hartym:1749_doctest_report_format into ae07985 on pytest-dev:features.

"""
return ('udiff', 'cdiff', 'ndiff', 'only_first_failure', 'none', )

def _get_report_choices():
Copy link
Member

Choose a reason for hiding this comment

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

Excellent! 👍

@coveralls
Copy link

coveralls commented Jul 23, 2016

Coverage Status

Coverage increased (+0.02%) to 93.057% when pulling f8f690d on hartym:1749_doctest_report_format into ae07985 on pytest-dev:features.

@coveralls
Copy link

coveralls commented Jul 23, 2016

Coverage Status

Coverage increased (+0.02%) to 93.057% when pulling f8f690d on hartym:1749_doctest_report_format into ae07985 on pytest-dev:features.

@hackebrot
Copy link
Member

Great job @hartym! 😃

@nicoddemus
Copy link
Member

I second that, this a very well written PR, thanks @hartym! 😄

@hackebrot
Copy link
Member

EuroPython sprint already paid out for me 😁

_get_report_choices_keys(),
(doctest.REPORT_UDIFF, doctest.REPORT_CDIFF, doctest.REPORT_NDIFF, doctest.REPORT_ONLY_FIRST_FAILURE, 0, )
)
)
Copy link
Member

@The-Compiler The-Compiler Jul 23, 2016

Choose a reason for hiding this comment

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

What about something like:

options = {
    'udiff': doctest.REPORT_UDIFF,
    ...
}
assert set(options) == set(_get_report_choices_keys())
return options

While being a slight duplication, that would make it easier to read IMHO, would make it work regardless of the order, and would fail if the keys diverge.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will try something else about this, hold on. Will opt for the roof also, will get fresher code :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rewrote the implementation in 51fa244

@nicoddemus
Copy link
Member

@hartym just checking, did you see my last comment about parametrizing test_doctest_report_none_or_only_first_failure? If you don't have time to do it I would be happy to merge as it is. 👍

@hartym
Copy link
Contributor Author

hartym commented Jul 23, 2016

Fixed in d5a70ac ;)
The temperature in the room makes it easy to miss comments, sorry ...

@nicoddemus
Copy link
Member

Thanks a lot! 😁

Merging as soon as the CI passes again.

@The-Compiler
Copy link
Member

The temperature in the room makes it easy to miss comments, sorry ...

The temperature is more comfortable outside on the roof 😉

@coveralls
Copy link

coveralls commented Jul 23, 2016

Coverage Status

Coverage increased (+0.02%) to 93.057% when pulling d5a70ac on hartym:1749_doctest_report_format into ae07985 on pytest-dev:features.

@hackebrot
Copy link
Member

@kvas-it and myself are sitting outside as well 😎

@nicoddemus
Copy link
Member

img

@hartym
Copy link
Contributor Author

hartym commented Jul 23, 2016

Ok, I implemented it differently so we avoid this strange "double method" thing, as @The-Compiler was suggesting. A bit more verbose, but definitely less error prone imho, what do you think ? (51fa244)

@hackebrot
Copy link
Member

Trust me @nicoddemus, we'd love to have you here! Maybe next year?

@@ -94,7 +111,7 @@ def repr_failure(self, excinfo):
message = excinfo.type.__name__
reprlocation = ReprFileLocation(filename, lineno, message)
checker = _get_checker()
REPORT_UDIFF = doctest.REPORT_UDIFF
REPORT_UDIFF = _get_report_choice(self.config.getoption("doctestreport"))
Copy link
Member

Choose a reason for hiding this comment

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

Heh we missed the variable name REPORT_UDIFF... should be probably report_choice or so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In 94731fc

@nicoddemus
Copy link
Member

Ok, I implemented it differently so we avoid this strange "double method" thing, as @The-Compiler was suggesting. A bit more verbose, but definitely less error prone imho, what do you think ?

I think it looks good, thanks!

@nicoddemus
Copy link
Member

Trust me @nicoddemus, we'd love to have you here! Maybe next year?

Maybe! 😄

@coveralls
Copy link

coveralls commented Jul 23, 2016

Coverage Status

Coverage increased (+0.02%) to 93.06% when pulling 94731fc on hartym:1749_doctest_report_format into ae07985 on pytest-dev:features.

@coveralls
Copy link

coveralls commented Jul 23, 2016

Coverage Status

Coverage increased (+0.02%) to 93.06% when pulling 94731fc on hartym:1749_doctest_report_format into ae07985 on pytest-dev:features.

@nicoddemus
Copy link
Member

Just waiting for CI to go green before merging.

Just took the opportunity to update the "what's new in pytest 3.0" post. 😉

@nicoddemus
Copy link
Member

Thanks again @hartym! 👍

@nicoddemus nicoddemus merged commit 9891593 into pytest-dev:features Jul 23, 2016
@hartym
Copy link
Contributor Author

hartym commented Jul 23, 2016

✌️ /me happy ; I guess I won't do more today (kind of slow walk more than sprint) but I'll be there tomorrow if there is some easy stuff for me.

@hartym hartym deleted the 1749_doctest_report_format branch July 23, 2016 15:58
@nicoddemus
Copy link
Member

We certainly appreciate it! 😄

@tomviner
Copy link
Contributor

Great work @hartym!

(A hint that @nicoddemus gave me is you can close issues via commit messages. So, next time, if you add e.g. fixes #1749 to a commit message, it'll close when the PR is merged! See for details: https://help.github.com/articles/closing-issues-via-commit-messages/ )

@nicoddemus
Copy link
Member

Just a heads up @tomviner: @hartym did in fact wrote "Fixes #1749" in one of the commits, but GitHub only closes issues when that commit is merged into master. 😁

@danilobellini
Copy link
Contributor

I've finished a plugin recently that has something to do with this new reporting feature: https://github.com/danilobellini/pytest-doctest-custom

I still didn't test it together with this new doctest-report, but I think expressions like "output format" would remind the internal doctest representation formatter to many people (which is actually what my plugin is about).

@nicoddemus
Copy link
Member

Cool 😎

@nicoddemus
Copy link
Member

Hey @danilobellini, please don't hesitate to follow up with moving your plugin to pytest-dev as we discussed. 😁

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.

7 participants