Skip to content

Presence of a plugin causes doctests a shared namespace to fail traceback with assertion #8059

Open
@jaraco

Description

@jaraco

In jaraco/jaraco.test#3, I've described an issue that appears to implicate some of the most edgy features of pytest and Python, in particular:

  • assert rewrite
  • doctests
  • namespace packages
  • plugins

Oh, joy.

In summary, the issue seems to be that:

The presence of an empty module as a plugin in a namespace shared by the package under test causes assert exceptions in doctests to be re-written, causing the output from those doctests to fail where they wouldn't otherwise, even if the plugin is disabled with -p no:....

As you can see from the tox execution in the downstream report, I'm using pytest 6.1.2 on Python 3.9.0 with jaraco.test 4.0.1 (the implicated plugin) on macOS 11.0.1 (latest stable everything as of this writing).

I don't yet have a minimal example, though you can check out jaraco/jaraco.itertools@e9f23a4 and run tox -- -k assert to see the error.

I expect (though haven't verified) that any of the following remedies might be possible:

  • Move the plugin to a package not sharing the jaraco namespace. I was considering creating pytest-enabler anyway.
  • Replace the bare assert with a raise AssertionError. I'll test that soon.
  • Update the test expectation to expect the rewritten assert output.
  • Replace the doctest with a unit test.

None of these workarounds would address the root cause, but instead avoid the confounding factors leading to the failed expectation.

I recognize this issue is probably too obscure to expect it to be fixed upstream, but I could really use some advice on how to proceed with an investigation. In particular, can you explain or point me to the implementation where doctests get special treatment for assert-rewrite (or vice-versa), especially any code that might be relevant for selectively affecting the modules-under-test or plugins?

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: doctestsrelated to the doctests builtin pluginstatus: help wanteddevelopers would like help from experts on this topictopic: rewriterelated to the assertion rewrite mechanism

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions