-
-
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
Doctest report format option (#1749) #1754
Doctest report format option (#1749) #1754
Conversation
…ogress as a few checks fail (related to pytest-dev#1749)
…tested things like "logging") for argument parsing (fixes pytest-dev#1749)
@@ -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 |
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.
Nit pick: "when displaying failed doctests (#1749). Thanks @hartym
for the PR." 😉
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.
Does that mean I should thank myself in the changelog? also removed the ticket reference, as it was making lint fail.
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.
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(): |
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.
Nitpick here: wouldn't be simpler to just have _get_report_choices()
and use _get_report_choices().keys()
when you need the keys instead?
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.
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.
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.
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. 😁
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.
In ec7695e
' 2 3 6', | ||
]) | ||
|
||
def test_doctest_report_none_or_only_first_failure(self, testdir): |
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.
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):
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.
In e229a27
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.
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',
])
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.
My bad, kind of applied dumbly your comment, did not remember about this other loop.
… from another as suggested by @nicoddemus in pr pytest-dev#1754
""" | ||
return ('udiff', 'cdiff', 'ndiff', 'only_first_failure', 'none', ) | ||
|
||
def _get_report_choices(): |
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.
Excellent! 👍
Great job @hartym! 😃 |
I second that, this a very well written PR, thanks @hartym! 😄 |
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, ) | ||
) | ||
) |
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.
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.
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.
I will try something else about this, hold on. Will opt for the roof also, will get fresher code :D
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.
Rewrote the implementation in 51fa244
@hartym just checking, did you see my last comment about parametrizing |
Fixed in d5a70ac ;) |
Thanks a lot! 😁 Merging as soon as the CI passes again. |
The temperature is more comfortable outside on the roof 😉 |
@kvas-it and myself are sitting outside as well 😎 |
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) |
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")) |
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.
Heh we missed the variable name REPORT_UDIFF
... should be probably report_choice
or so.
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.
In 94731fc
I think it looks good, thanks! |
Maybe! 😄 |
Just waiting for CI to go green before merging. Just took the opportunity to update the "what's new in pytest 3.0" post. 😉 |
Thanks again @hartym! 👍 |
✌️ /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. |
We certainly appreciate it! 😄 |
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. |
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). |
Cool 😎 |
Hey @danilobellini, please don't hesitate to follow up with moving your plugin to |
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.
master
; for new features, targetfeatures
AUTHORS
CHANGELOG
(choose any open position to avoid merge conflicts with other PRs)