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

Running single test function with `--doctest-modules` raises an error #3843

Closed
hoefling opened this Issue Aug 21, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@hoefling
Contributor

hoefling commented Aug 21, 2018

Origin: question on SO

Prep for reproducing:

$ mkdir issue
$ printf 'def test_spam():\n    assert True\n' > issue/test_eggs.py
$ pytest issue/test_eggs.py::test_spam
========================================================== test session starts ==========================================================
platform darwin -- Python 3.6.4, pytest-3.7.2, py-1.5.4, pluggy-0.7.1
rootdir: /private/tmp, inifile:
collected 1 item

issue/test_eggs.py .                                                                                                              [100%]

======================================================= 1 passed in 0.01 seconds ========================================================

Adding --doctest-modules to the previous command fails the test run:

$ pytest issue/test_eggs.py::test_spam --doctest-modules
========================================================== test session starts ==========================================================
platform darwin -- Python 3.6.4, pytest-3.7.2, py-1.5.4, pluggy-0.7.1
rootdir: /private/tmp, inifile:
collecting 0 items
===================================================== no tests ran in 0.00 seconds ======================================================
ERROR: not found: /private/tmp/issue/test_eggs.py::test_spam
(no name '/private/tmp/issue/test_eggs.py::test_spam' in any of [<DoctestModule 'issue/test_eggs.py'>, <Module 'issue/test_eggs.py'>])
@hoefling

This comment has been minimized.

Show comment
Hide comment
@hoefling

hoefling Aug 21, 2018

Contributor

I've added a simple test reproducing this issue; at least reproducible using Python 3.5/3.6/3.7 on the current master.

Contributor

hoefling commented Aug 21, 2018

I've added a simple test reproducing this issue; at least reproducible using Python 3.5/3.6/3.7 on the current master.

@nicoddemus

This comment has been minimized.

Show comment
Hide comment
@nicoddemus

nicoddemus Aug 21, 2018

Member

Thanks @hoefling for the report!

Member

nicoddemus commented Aug 21, 2018

Thanks @hoefling for the report!

nicoddemus added a commit to nicoddemus/pytest that referenced this issue Aug 22, 2018

Fix collection error when tests is specified with --doctest-modules
The problem was that _matchnodes would receive two items: [DoctestModule, Module]. It would then collect the first one, *cache it*, and fail to match against the name in the command line. Next, it would reuse the cached item (DoctestModule) instead of collecting the Module which would eventually find the "test" name on it.

Added the type of the node to the cache key to avoid this problem, although I'm not a big fan of caches that have different key types.

Fix #3843

@nicoddemus nicoddemus closed this in #3846 Aug 22, 2018

@hoefling

This comment has been minimized.

Show comment
Hide comment
@hoefling

hoefling Aug 22, 2018

Contributor

Nice, thanks for the quick fix!

Contributor

hoefling commented Aug 22, 2018

Nice, thanks for the quick fix!

cmccandless added a commit to cmccandless/multisite that referenced this issue Aug 30, 2018

Update pytest to 3.7.4 (#10)
This PR updates [pytest](https://pypi.org/project/pytest) from **3.7.2** to **3.7.4**.



<details>
  <summary>Changelog</summary>
  
  
   ### 3.7.4
   ```
   =========================

Bug Fixes
---------

- `3506 &lt;https://github.com/pytest-dev/pytest/issues/3506&gt;`_: Fix possible infinite recursion when writing ``.pyc`` files.


- `3853 &lt;https://github.com/pytest-dev/pytest/issues/3853&gt;`_: Cache plugin now obeys the ``-q`` flag when ``--last-failed`` and ``--failed-first`` flags are used.


- `3883 &lt;https://github.com/pytest-dev/pytest/issues/3883&gt;`_: Fix bad console output when using ``console_output_style=classic``.


- `3888 &lt;https://github.com/pytest-dev/pytest/issues/3888&gt;`_: Fix macOS specific code using ``capturemanager`` plugin in doctests.



Improved Documentation
----------------------

- `3902 &lt;https://github.com/pytest-dev/pytest/issues/3902&gt;`_: Fix pytest.org links
   ```
   
  
  
   ### 3.7.3
   ```
   =========================

Bug Fixes
---------

- `3033 &lt;https://github.com/pytest-dev/pytest/issues/3033&gt;`_: Fixtures during teardown can again use ``capsys`` and ``capfd`` to inspect output captured during tests.


- `3773 &lt;https://github.com/pytest-dev/pytest/issues/3773&gt;`_: Fix collection of tests from ``__init__.py`` files if they match the ``python_files`` configuration option.


- `3796 &lt;https://github.com/pytest-dev/pytest/issues/3796&gt;`_: Fix issue where teardown of fixtures of consecutive sub-packages were executed once, at the end of the outer
  package.


- `3816 &lt;https://github.com/pytest-dev/pytest/issues/3816&gt;`_: Fix bug where ``--show-capture=no`` option would still show logs printed during fixture teardown.


- `3819 &lt;https://github.com/pytest-dev/pytest/issues/3819&gt;`_: Fix ``stdout/stderr`` not getting captured when real-time cli logging is active.


- `3843 &lt;https://github.com/pytest-dev/pytest/issues/3843&gt;`_: Fix collection error when specifying test functions directly in the command line using ``test.py::test`` syntax together with ``--doctest-modules``.


- `3848 &lt;https://github.com/pytest-dev/pytest/issues/3848&gt;`_: Fix bugs where unicode arguments could not be passed to ``testdir.runpytest`` on Python 2.


- `3854 &lt;https://github.com/pytest-dev/pytest/issues/3854&gt;`_: Fix double collection of tests within packages when the filename starts with a capital letter.



Improved Documentation
----------------------

- `3824 &lt;https://github.com/pytest-dev/pytest/issues/3824&gt;`_: Added example for multiple glob pattern matches in ``python_files``.


- `3833 &lt;https://github.com/pytest-dev/pytest/issues/3833&gt;`_: Added missing docs for ``pytester.Testdir``.


- `3870 &lt;https://github.com/pytest-dev/pytest/issues/3870&gt;`_: Correct documentation for setuptools integration.



Trivial/Internal Changes
------------------------

- `3826 &lt;https://github.com/pytest-dev/pytest/issues/3826&gt;`_: Replace broken type annotations with type comments.


- `3845 &lt;https://github.com/pytest-dev/pytest/issues/3845&gt;`_: Remove a reference to issue `568 &lt;https://github.com/pytest-dev/pytest/issues/568&gt;`_ from the documentation, which has since been
  fixed.
   ```
   
  
</details>


 

<details>
  <summary>Links</summary>
  
  - PyPI: https://pypi.org/project/pytest
  - Changelog: https://pyup.io/changelogs/pytest/
  - Homepage: https://docs.pytest.org/en/latest/
</details>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment