-
-
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 plugin runs when unwanted #4954
Comments
Haven't investigate, but make sure that |
Related code: https://github.com/blueyed/pytest/blob/033849a31ec7d2b9f0493fa51c77289eab657af1/src/_pytest/doctest.py#L104-L107. The glob pattern is ignored for txt and rst files given on the command line explicitly. Why do you specify |
I was very sure that "The glob pattern is ignored for txt and rst files given on the command line explicitly." feels like a bug to me. Why specify |
Yeah.. but if you specify "README.rst" it runs the (doc)tests from it. It is like with |
It evidently does, but why should it? it doesn't when I don't otherwise limit discovery. To be clear: this is far from a show stopper, but it is a bit of a wart and it would be great to find a way to fix it! |
But |
If you pass a file explicitly on the command-line, pytest will run that file as a test, regardless of test file pattern configuration or I think the rationale is that if you are explicitly passing the file in the command-line, you are telling pytest to run tests from that file. Not sure what were the requirements that lead to this, but I don't think we should change this without a good reason because this will certainly break some workflows out there. |
[fixed this comment up as I realised I was misreading some output] Sorry, but this doesn't feel right.
Now, if I specify an item within the file, things work as expected:
The problem is that these tests shared state within a module, they're testing the examples within documentation using Sybil, so I really want to be able to run a single file without the annoying and erroneous doctest stuff kicking in. How do I do that? |
What is that? I suggest digging into the code maybe yourself (I've left a pointer already). (btw: with 4.4 it would also display "testpaths: …" in the header, I wonder if that covers this case also?) |
No, I mean conftest.py. |
It is not really, but I just wondered if files for doctests would show up there (like they should). |
Just to be clear: I'm not using doctests and I don't want to be using doctests. I want pytest to stop erroneously treating my non-doctest .rst files as doctests, which it only does if I specify a particular file on the command line. My currently workaround is to do:
That works fine, so there's no massive priority on fixing this, but it feels like you're trying to tell me it's not a bug, in which case I will respectfully disagree ;-) |
Try |
I already have a workaround thanks... |
And I agree that the collection logic in the doctest plugin is a bit wonky. As for your workaround: it will collect all files, and then filter based on a pattern, which is slower than collecting just one file. |
Just to note that this is still an issue in pytest 6, but that putting |
Thanks @cjw296, Not sure how we could change the defaults so they don't break existing workflows though. Any ideas? If so I suggest we open a new "proposal" with a plan to deprecate automatically running doctests in |
This file fails when run explicitly with pytest:
Things work fine if I just
pytest
in the root directory. The problem is that the doctest plugin is kicking in when it has not been requested, and indeed even when I try and explicitly stop it from working on this file. I use sybil for testing examples in my documentation as it provides for more flexibility.Here's my full environment:
The text was updated successfully, but these errors were encountered: