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

ModuleNotFoundError with pytest-doctestplus #872

Open
PeterJCLaw opened this issue Jul 7, 2024 · 3 comments
Open

ModuleNotFoundError with pytest-doctestplus #872

PeterJCLaw opened this issue Jul 7, 2024 · 3 comments
Milestone

Comments

@PeterJCLaw
Copy link

I'm hitting an issue using pytest-asyncio alongside pytest-doctestplus, a plugin for detecting tests in documentation. I admittedly don't know which plugin might need to change here, though given the popularity of doctests it would be great if the two worked together.

Reproduce

Create a README.md containing:

``` python
def test():
    pass

```
``` pycon
>>> 1 + 1
2

```

Then run:

$ pip install pytest-asyncio pytest-doctestplus
...
$ pytest --doctest-plus --doctest-glob '*.md'
=========================== test session starts ============================
platform linux -- Python 3.10.12, pytest-8.2.2, pluggy-1.5.0
rootdir: /tmp/bees
plugins: doctestplus-1.2.1, asyncio-0.23.7
asyncio: mode=strict
collected 0 items / 1 error                                                

================================== ERRORS ==================================
________________________ ERROR collecting README.md ________________________
ImportError while importing test module '/tmp/bees/README.md'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'README'
========================= short test summary info ==========================
ERROR README.md
!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!
============================= 1 error in 0.20s =============================

Cross reference: scientific-python/pytest-doctestplus#256

@seifertm
Copy link
Contributor

seifertm commented Jul 15, 2024

It's not unlikely that pytest-asyncio is at fault here. The plugin has some pretty ugly code that runs during test collection:
https://github.com/pytest-dev/pytest-asyncio/blob/v0.23.7/pytest_asyncio/plugin.py#L575-L653

Essentially, it can only deal with standard pytest collectors and its subclasses. This could be a reason for the error you're seeing.

What's the collector type of the README file in your example?

@PeterJCLaw
Copy link
Author

What's the collector type of the README file in your example?

I don't know. @bsipocz as you'd looked at this from the doctestplus side, perhaps you can help here?

@bsipocz
Copy link

bsipocz commented Jul 15, 2024

We certainly customised the collector, but not as a subclass, so it all could be the source of the problem. As I see there is certainly more care put in the API docs collection than in the narrative docs files, so I'll try a few things this week to see if we have an easy fix for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants