Skip to content

MNT: Compat with pytest 5.4.0 #95

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

Closed
wants to merge 1 commit into from

Conversation

pllim
Copy link
Contributor

@pllim pllim commented Mar 13, 2020

@pllim pllim added the bug label Mar 13, 2020
@pllim pllim requested review from astrofrog and bsipocz March 13, 2020 17:04
@bsipocz
Copy link
Member

bsipocz commented Mar 13, 2020

failure is related, I can come back in the evening, but not earlier.

@pllim

This comment has been minimized.

@pllim
Copy link
Contributor Author

pllim commented Mar 13, 2020

Update: I don't have enough pytest-fu to fix the error. Looking at the code, the thing that seems most intuitive is to have DocTestTextfilePlus inherit from DoctestTextfile but doing that broke other things. I tried several other hacks including copying over a from_parent signature with fspath but that didn't work either. I also tried switching the two parent classes of DocTestTextfilePlus.

https://github.com/pytest-dev/pytest/blob/d7f01a90eba4b3bde06e7827ccaf12252f6116d6/src/_pytest/doctest.py#L364

I wonder if @RonnyPfannschmidt or @nicoddemus has any insights for us.

Relevant CI log: https://travis-ci.org/github/astropy/pytest-doctestplus/jobs/662066066

    x = self._doctest_textfile_item_cls.from_parent(
E   TypeError: from_parent() got an unexpected keyword argument 'fspath'

@nicoddemus
Copy link
Contributor

nicoddemus commented Mar 13, 2020

Hi folks,

I will wait for @RonnyPfannschmidt to chime in as he is more familiar with the from_parent changes. 👍

@RonnyPfannschmidt
Copy link

RonnyPfannschmidt commented Mar 14, 2020

i took a initial look, inheriting from both a item and a collector like module was broken to begin with,
instead of item,

as far as i can tell doctestplus changes a assumption in tying to run a complete file as test,
it should use 2 nodes here, one for collecting the file, one for running the single big test

combining test items and file collectors works purely by accident, the new code added a to the point constructor for the test item which broke the file collector bits that came in as well

@pllim
Copy link
Contributor Author

pllim commented Mar 15, 2020

Thanks, @RonnyPfannschmidt . But, oh dear, sounds like a complete refactoring is needed to make this compatible and I am not sure if I am up for the task.

@pllim pllim mentioned this pull request Mar 16, 2020
2 tasks
@@ -272,7 +280,7 @@ def parse(self, s, name=None):
if ext not in comment_characters:
warnings.warn("file format '{}' is not recognized, assuming "
"'{}' as the comment character."
.format(ext, comment_characters['rst']))
.format(ext, comment_characters['.rst']))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is already fixed in #101 and should be gone after rebase.

if PYTEST_LT_5_4:
yield DoctestItem(test.name, self, runner, test)
else:
yield DoctestItem.from_parent(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This does not work because I think now Python's doctest tries to read in the docstring as it is defined in the test file, not via testdir fixture. I stared at the code here, the code in pytest, and Python doc, but couldn't figure out a path forward.

Simply renaming the old runtest to collect doesn't work either:

https://github.com/astropy/pytest-doctestplus/blob/9975e23d178465c00b75f6b2f178f89e2245b540/pytest_doctestplus/plugin.py#L218

@pllim
Copy link
Contributor Author

pllim commented Mar 16, 2020

Wait a minute, my local test is totally different from Travis CI results. I cannot even get the tests to collect. My brain hurts.

$ pytest  --doctest-plus
============================= test session starts ==============================
platform linux -- Python 3.7.3, pytest-5.4.1, py-1.8.0, pluggy-0.12.0
Matplotlib: 3.1.1
Freetype: 2.10.0
rootdir: .../astropy/pytest-doctestplus, inifile: setup.cfg, testpaths: tests, pytest_doctestplus
plugins: remotedata-0.3.1, openfiles-0.3.2, arraydiff-0.3, astropy-header-0.1.2, forked-1.1.3, xdist-1.30.0, mpl-0.11, cov-2.8.1, filter-subpackage-0.1.1, hypothesis-5.5.2, ci-watson-0.0.0.dev76+g4b73d3b5, asdf-2.4.0.dev63+gb67cb02, doctestplus-0.6.0.dev0
collected 28 items / 1 error / 27 selected                                     

==================================== ERRORS ====================================
__________________ ERROR collecting tests/test_doctestplus.py __________________
pytest_doctestplus/plugin.py:231: in collect
    test = parser.get_doctest(text, globs, name, filename, 0)
.../doctest.py:668: in get_doctest
    return DocTest(self.get_examples(string, name), globs,
.../doctest.py:682: in get_examples
    return [x for x in self.parse(string, name)
pytest_doctestplus/plugin.py:268: in parse
    result = doctest.DocTestParser.parse(self, s, name=name)
.../doctest.py:644: in parse
    self._parse_example(m, name, lineno)
.../doctest.py:714: in _parse_example
    lineno + len(source_lines))
.../doctest.py:800: in _check_prefix
    (lineno+i+1, name, line))
E   ValueError: line 30 of the docstring for test_doctestplus.py has inconsistent leading whitespace: '    """'
=========================== short test summary info ============================
ERROR tests/test_doctestplus.py - ValueError: line 30 of the docstring for te...
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.22s ===============================

@pllim
Copy link
Contributor Author

pllim commented Apr 3, 2020

Closing in favor of #103 . Thanks, @saimn !

@pllim pllim closed this Apr 3, 2020
@pllim pllim deleted the pytest-5.4.0 branch April 3, 2020 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deprecation warning with pytest 5.4.0
4 participants