Skip to content

Compatibility with Pytest 5.4#103

Merged
bsipocz merged 7 commits intoscientific-python:masterfrom
saimn:pytest54
Apr 29, 2020
Merged

Compatibility with Pytest 5.4#103
bsipocz merged 7 commits intoscientific-python:masterfrom
saimn:pytest54

Conversation

@saimn
Copy link
Contributor

@saimn saimn commented Apr 1, 2020

This is quite similar to #95, but I started from scratch and porting some code from pytest's doctest plugin which probably changed a lot since the first version of doctestplus.

With these changes I had a few tests failing, and I actually don't understand why the tests were not failing before so I updated the tests. Please review, not sure who knows this code best ?

"""
)
testdir.inline_run(p, '--doctest-plus', '--doctest-rst').assertoutcome(passed=1)
testdir.inline_run(p, '--doctest-plus', '--doctest-rst').assertoutcome(skipped=1)
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 testing that the test is skipped because of a missing import, I guess the outcome should be "skipped".

Copy link
Member

Choose a reason for hiding this comment

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

how did all of these tests work before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See my comment below: #103 (review)

)
# passed because 'pytest<1.0' was not satisfied and 'assert 0' was not evaluated
testdir.inline_run(p, '--doctest-plus', '--doctest-rst').assertoutcome(passed=1)
testdir.inline_run(p, '--doctest-plus', '--doctest-rst').assertoutcome(skipped=1)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same here.

'--doctest-glob', '*.tex',
'--doctest-glob', '*.txt'
).assertoutcome(passed=3)
).assertoutcome(passed=0)
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 testing that the tests are commented, so they are not run, they should not "pass". Same below.

str(self.fspath), module_relative=False,
optionflags=options, parser=DocTestParserPlus(),
extraglobs=dict(getfixture=fixture_request.getfixturevalue),
raise_on_error=True, verbose=False, encoding='utf-8')
Copy link
Contributor Author

@saimn saimn Apr 1, 2020

Choose a reason for hiding this comment

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

Ok so the tests differences are due to this removal of doctest.testfile, which is because I basically copied what pytest's doctest plugin is doing, to remove the multiple inheritance, and use collect instead of runtest. I don't know why the old code was doing it another way so ... 🤷‍♂️

@bsipocz
Copy link
Member

bsipocz commented Apr 3, 2020

There are still issues with pytest><4 versions. Those are however 1.5 years old, so we may even consider dropping them if the fix is more complicated than necessary.

@saimn
Copy link
Contributor Author

saimn commented Apr 3, 2020

Oh sorry, I thought I read somewhere that pytest's minversion was 5.0, but I must have mistaken it for another package. Anyway, for tests dependencies I think it is easier to require recent versions, so indeed I'd be happy if we can drop old versions.

@bsipocz
Copy link
Member

bsipocz commented Apr 3, 2020

ok, let's wait for @astrofrog's opinion. And nominally @eteq is also listed as testing maintainer, in case he wants to chime in...

Copy link
Contributor

@astrofrog astrofrog left a comment

Choose a reason for hiding this comment

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

I'd be fine with dropping support for pytest<4 - I'm not super familiar with this code, but if (a) the test suite here passes and (b) if the astropy core test suite passes with this, then 👍 from me 😄

@bsipocz
Copy link
Member

bsipocz commented Apr 3, 2020

@saimn - Shall I open a separate PR for the travis updates, or push directly to your branch? There are other unrelated issues with the config, so would ideally all need to be cleaned up before this is merged (to be sure this works).

@saimn
Copy link
Contributor Author

saimn commented Apr 4, 2020

@astrofrog - yes it works fine with astropy. The test cases I had to changes were edge cases, and I mostly copied code from pytest's doctest plugin, so hopefully it should be fine.

@bsipocz - sure, push here if you want. The travis config indeed needs some updates.

@bsipocz bsipocz force-pushed the pytest54 branch 2 times, most recently from b466e88 to 1e4152b Compare April 23, 2020 05:30
@bsipocz
Copy link
Member

bsipocz commented Apr 23, 2020

This now drops support for python <3.6 as well as for pytest <4.

@bsipocz bsipocz requested a review from astrofrog April 23, 2020 05:56
@bsipocz
Copy link
Member

bsipocz commented Apr 23, 2020

I've also added a job for pytest dev version, and switched on the weekly cron.

Now this is very much ready for merging.

@bsipocz bsipocz mentioned this pull request Apr 29, 2020
@bsipocz
Copy link
Member

bsipocz commented Apr 29, 2020

No vetoes here in the past week, so I'm merging and will go ahead with a release fairly soon.

Thank you @saimn for picking this up and fixing it.

@bsipocz bsipocz merged commit d4e540d into scientific-python:master Apr 29, 2020
@saimn saimn deleted the pytest54 branch April 29, 2020 19:10
Comment on lines +171 to +174
if self.config.getvalue("doctest_ignore_import_errors"):
pytest.skip("unable to import module %r" % self.fspath)
else:
raise
Copy link
Contributor

Choose a reason for hiding this comment

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

This changes dramatically the behavior of the plugin. Now if any module in the repo using this plugin has import failures, it will cause a collection error. In the past for this plugin, this was ignored. I see that using --doctest-ignore-import-errors can turn this off, but it would be good to document this in the README and the release notes.

Copy link
Contributor

Choose a reason for hiding this comment

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

See astropy/astropy#10242 for a possible fix in astropy btw, we should discuss there whether that is the correct fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, sorry for the breakage. The goal was just to reduce the number of difference with pytest's doctest plugin, because of lot of the code here is copied from there, and reducing the differences should make it easier to maintain...
But yeah as previously this was ignored by default it is probably easier to fix this here.

Copy link
Contributor

Choose a reason for hiding this comment

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

No worries. I think it is easy to add --doctest-ignore-import-errors to addopts in setup.cfg, it was just surprising. And it took some time to debug. Hence the desire of making this clear in the documentation.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, it was nice finding out we had tumbleweed code laying about that had imports that didn't work.

I agree that having its behavior similar to pytest's doctest is good. The more things that are the same, not only easier to maintain, but the less unexpected behavior for people using the plugin as an extension or replacement of the pytest one.

Copy link
Member

Choose a reason for hiding this comment

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

see a few open issues about moving these upstream and consolidate the differences between doctest and doctestplus. The blocking factor is time, and now I also think it's better to wait for the situation at pytest to resolve.

Copy link
Member

Choose a reason for hiding this comment

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

also, it's my bad that I didn't pick this up during the review, I suppose I put too much trust in tests and was just too happy when this PR finally had a green status.

@dstansby
Copy link
Contributor

Has this made its way into a release yet?

@saimn
Copy link
Contributor Author

saimn commented Jul 13, 2020

@dstansby
Copy link
Contributor

Thanks!

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.

5 participants