GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — --pyargs does not understand namespace packages · Issue #478 · pytest-dev/pytest

--pyargs does not understand namespace packages #478

New issue
Copy link
New issue
Copy link
Closed
#13426
Closed
--pyargs does not understand namespace packages#478
#13426
Copy link
Labels
status: help wanteddevelopers would like help from experts on this topictype: bugproblem that needs to be addressed

Description

@pytestbot
pytestbot
opened on Mar 6, 2014
Issue body actions

Originally reported by: Wolfgang Schnerring (BitBucket: wosc, GitHub: wosc)


The pyargs resolution does not understand namespace packages when the different contributing packages are installed as eggs (which is the layout used by zc.buildout and also pip install --egg, see http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages). It looks like this:

site-packages/
    zope.asdf.egg/
        zope/
            asdf/
                ...
    zope.qwer.egg/
        zope/
            qwer/
                ...

This is a well supported layout, which means import zope.asdf and import zope.qwer work just fine (the specification is something to the effect of, if there is more than one directory that claims to be package "zope", there is no guarantee which one you will actually get when you say import zope, but all subpackages will be accessible regardless).

But py.test --pyargs zope.asdf will work, while py.test --pyargs zope.qwer will say "file or package not found" (it might also be the other way around, so zope.qwer works, but zope.asdf doesn't).

This is because _pytest.main.Session._tryconvertpyarg does not actually rely on the Python import mechanism to do the resolution (I'm not sure why, I'm guessing it's to support collecting tests outside of packages?). Instead it splits the argument on dots and loads the parts from the import system, assuming their filesystem location is the one that matters -- which is incorrect. In the example, trying to resolve zope.qwer, it will first resolve zope, which results in a random matching entry, e.g site-packages/zope.asdf/zope/__init__.py. It then assumes that the rest of the name must exist below this specific directory, thus never finding zope.qwer.


  • Bitbucket: https://bitbucket.org/pytest-dev/pytest/issue/478

Activity

Next
  1. pytestbot
    added
    type: bugproblem that needs to be addressed
    on Jun 15, 2015
  2. scottpurdy commented on Sep 12, 2015

    @scottpurdy
    scottpurdy
    on Sep 12, 2015
    More actions

    The relevant code is here.

    Instead of iteratively importing from the top level package, could it try importing from the full path first and, if it fails, iteratively pop the rightmost element off until it succeeds in importing and then do the file lookup from there?

    I'm happy to implement a solution if there is a reasonable option available.

  3. RonnyPfannschmidt commented on Sep 12, 2015

    @RonnyPfannschmidt
    RonnyPfannschmidt
    on Sep 12, 2015
    Member
    More actions

    Since this is a setuptools mess, how about supporting module.path:object.path just like entry points of setuptools?

  4. scottpurdy commented on Sep 14, 2015

    @scottpurdy
    scottpurdy
    on Sep 14, 2015
    More actions

    That seems fine to me. Does it work for packages though? I don't have a strong opinion on the discovery mechanism as long as it supports namespace packages.

  5. RonnyPfannschmidt commented on Sep 14, 2015

    @RonnyPfannschmidt
    RonnyPfannschmidt
    on Sep 14, 2015
    Member
    More actions

    not sure off-hand, i'll probably need a while before i can touch it due to volunteering time constraints

  6. RonnyPfannschmidt commented on Apr 20, 2016

    @RonnyPfannschmidt
    RonnyPfannschmidt
    on Apr 20, 2016
    Member
    More actions

    @scottpurdy is this sill an issue, with the gradual phasing out of eggs im thinking of letting this one be unless someone makes a pr

  7. RonnyPfannschmidt
    added
    status: help wanteddevelopers would like help from experts on this topic
    on Apr 20, 2016
  8. scottpurdy commented on Apr 20, 2016

    @scottpurdy
    scottpurdy
    on Apr 20, 2016
    More actions

    Not super high priority for me or I'd help out. Are eggs really being phased out?

  9. RonnyPfannschmidt commented on Apr 21, 2016

    @RonnyPfannschmidt
    RonnyPfannschmidt
    on Apr 21, 2016
    Member
    More actions

    yes, its no longer part of the equation in modern packaging tools
    the common standard way of installation is pip+wheel

  10. eeaston commented on May 23, 2016

    @eeaston
    eeaston
    on May 23, 2016
    More actions

    .. unless you want to support zip importing, which is really important for slow filesystems like NFS. This bug is related to #1445 - the test collector doesn't support zipfile importing either.
    If I get some time soon I'll have a go at fixing this, the only workaround at the moment I can find is:

    easy_install --always-unzip zope.asdf.egg
    py.test $(python -c "import pkg_resources; print pkg_resources.get_distribution('zope.asdf').location")
    
  11. enkore commented on Nov 2, 2016

    @enkore
    enkore
    on Nov 2, 2016
    More actions

    This is kinda easy to trip over when using --pyargs, since one forgotten __init__.py lets py.test miraculously gloss over packages.

    If a fix is complex, maybe just print a hint? Right now it says:

    ERROR: file or package not found: somepkg
    

    When we're on a Python supporting NS packages and --pyargs was used it could say something like...

    ERROR: file or package not found: somepkg (missing __init__.py?)
    
    Reacted by Ronny Pfannschmidt and Duncan Betts
  12. RonnyPfannschmidt commented on Nov 2, 2016

    @RonnyPfannschmidt
    RonnyPfannschmidt
    on Nov 2, 2016
    Member
    More actions

    @enkore very good point

  13. DuncanBetts
    added a commit that references this issue on Nov 24, 2016

    Add hint of Issue pytest-dev#478 to error text

    ba3c1d2
  14. DuncanBetts commented on Nov 24, 2016

    @DuncanBetts
    DuncanBetts
    on Nov 24, 2016
    Contributor
    More actions

    I have made a Pull Request #2081 for commit ba3c1d2. Apologies if I should have waited for further discussion.

  15. nicoddemus commented on Nov 24, 2016

    @nicoddemus
    nicoddemus
    on Nov 24, 2016
    Member
    More actions

    Apologies if I should have waited for further discussion.

    Not at all. It's no harm opening a PR, even if to entice more discussion. But I think adding just the message should be enough for this issue for now.

  16. 12 remaining items

  17. ttung
    added 2 commits that reference this issue on Jan 27, 2020

    Make napari/tests a package

    0e3c93e

    Make napari/tests a package

    84b1bdc
  18. karlicoss
    added 4 commits that reference this issue on May 16, 2025

    Discover tests inside namespace packages via `--pyargs`

    502b793

    Support PEP420 (implicit namespace packages) as `--pyargs` target.

    98ac453

    Support PEP420 (implicit namespace packages) as `--pyargs` target.

    2ebcf5d

    Support PEP420 (implicit namespace packages) as `--pyargs` target.

    f0576dc
  19. karlicoss
    added a commit that references this issue on Jul 9, 2025

    Support PEP420 (implicit namespace packages) as `--pyargs` target.

    864079f
  20. nicoddemus
    closed this as completedin c02465con Jul 12, 2025
  21. pull
    added 2 commits that reference this issue on Jul 12, 2025

    Support PEP420 (implicit namespace packages) as `--pyargs` target. (p…

    This issue will close once commit c02465c is merged into the 'main' branch.
    c02465c

    Support PEP420 (implicit namespace packages) as `--pyargs` target. (p…

    This issue will close once commit e078e0c is merged into the 'main' branch.
    e078e0c
  22. 736-c41-2c1-e464fc974
    added 2 commits that reference this issue on Feb 4, 2026

    chore(deps): update pytest (major)

    01f4e67

    Merge branch 'renovate/pytest-9.x' into 'main'

    d08c4bc
  23. MateoGreil
    added a commit that references this issue on Jul 4, 2026

    🔒️ Update dependency pytest to v9 [SECURITY] (#16)

    d97ea28
  24. luketainton
    added a commit that references this issue on Jul 19, 2026

    [SECURITY] Update dependency pytest to v9 [SECURITY] (#2)

    fca183b
  25. Djeex
    added a commit that references this issue on Aug 31, 2026

    Update dependency pytest to v9 (#35)

    f96ce2f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: help wanteddevelopers would like help from experts on this topictype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.