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 discovery for zipped packages/unpacked wheels/eggs · Issue #1445 · pytest-dev/pytest

--pyargs discovery for zipped packages/unpacked wheels/eggs #1445

New issue
Copy link
New issue
Copy link
Open
Open
--pyargs discovery for zipped packages/unpacked wheels/eggs#1445
Copy link
Labels
topic: collectionrelated to the collection phasetype: enhancementnew feature or API change, should be merged into features branch

Description

@bjodah
bjodah
opened on Mar 9, 2016
Issue body actions

EDIT:

Using py.test --pyargs mypackage does not seem to work for .egg distributed packages.
Adding

[easy_install]
zip_ok = False

to setup.cfg seems to be a viable fix until py.test supports zipped packages.

Original issue text:

Using py.test --pyargs mypackage under a conda environment seems to be broken.
I've reported it here: conda/conda#2075

I am reposting it here in case someone has an idea what might be going on here.
Here is a Dockerfile to reproduce the bug:

FROM continuumio/miniconda:3.19.0
MAINTAINER Björn Dahlgren <[email protected]>
ENV PATH /opt/miniconda2/bin:$PATH
RUN git clone https://github.com/bjodah/dummypkg.git && \
    cd dummypkg && \
    conda install conda-build pytest && \
    conda build conda-recipe && \
    conda install --use-local dummypkg
RUN cd /tmp && \
    python -c 'import dummypkg; print(dummypkg.__file__)' && \
    python -m pytest --pyargs dummypkg

Running docker build generates the following output:

$ docker build revised-docker-environment/
Sending build context to Docker daemon 2.048 kB
Sending build context to Docker daemon 
Step 0 : FROM continuumio/miniconda:3.19.0
 ---> bc9d0fb804ac
Step 1 : MAINTAINER Björn Dahlgren <[email protected]>
 ---> Using cache
 ---> f81cd6785b68
Step 2 : ENV PATH /opt/miniconda2/bin:$PATH
 ---> Using cache
 ---> 3227b31b6bd9
Step 3 : RUN git clone https://github.com/bjodah/dummypkg.git &&     cd dummypkg &&     conda install conda-build pytest &&     conda build conda-recipe &&     conda install --use-local dummypkg
 ---> Using cache
 ---> 6765cf1fae4d
Step 4 : RUN cd /tmp &&     python -c 'import dummypkg; print(dummypkg.__file__)' &&     python -m pytest --pyargs dummypkg
 ---> Running in e9c721e5c4c2
/opt/conda/lib/python2.7/site-packages/dummypkg-0.1.0-py2.7.egg/dummypkg/__init__.pyc
============================= test session starts ==============================
platform linux2 -- Python 2.7.10, pytest-2.8.5, py-1.4.31, pluggy-0.3.1
rootdir: /tmp, inifile: 

========================= no tests ran in 0.00 seconds =========================
ERROR: file or package not found: dummypkg
INFO[0000] The command [/bin/sh -c cd /tmp &&     python -c 'import dummypkg; print(dummypkg.__file__)' &&     python -m pytest --pyargs dummypkg] returned a non-zero code: 4 

Activity

  1. nicoddemus commented on Mar 9, 2016

    @nicoddemus
    nicoddemus
    on Mar 9, 2016
    Member
    More actions

    I tried your recipe on Windows (after creating an appropriate bld.bat) without Docker, and I see the same issue. I noticed though that your recipe is creating an egg package:

    λ conda package -L dummypkg
    
    INFO: The location for available packages: E:\Miniconda\pkgs
    INFO: All files belonging to 'dummypkg-0.1.0-py27_0' package:
    
    E:\Miniconda\pkgs/dummypkg-0.1.0-py27_0/info/files
    E:\Miniconda\pkgs/dummypkg-0.1.0-py27_0/info/index.json
    E:\Miniconda\pkgs/dummypkg-0.1.0-py27_0/info/recipe.json
    E:\Miniconda\pkgs/dummypkg-0.1.0-py27_0/info/recipe/bld.bat
    E:\Miniconda\pkgs/dummypkg-0.1.0-py27_0/info/recipe/build.sh
    E:\Miniconda\pkgs/dummypkg-0.1.0-py27_0/info/recipe/meta.yaml
    E:\Miniconda\pkgs/dummypkg-0.1.0-py27_0/info/recipe/run_test.py
    E:\Miniconda\pkgs/dummypkg-0.1.0-py27_0/Lib/site-packages/dummypkg-0.1.0-py2.7.egg
    E:\Miniconda\pkgs/dummypkg-0.1.0-py27_0/Lib/site-packages/dummypkg.pth
    

    I'm not sure, but perhaps py.test can't load tests from eggs?

    For the record, I added this to your recipe:

    build:
      preserve_egg_dir: True

    But still the package only contained the .egg file, while I expected it to also contain the egg dir... I don't have time right now to investigate this further, but this might give you some hint.

  2. nicoddemus
    added
    topic: collectionrelated to the collection phase
    on Mar 9, 2016
  3. bjodah commented on Mar 10, 2016

    @bjodah
    bjodah
    on Mar 10, 2016
    Author
    More actions

    @nicoddemus spot on! This fixes it:
    https://github.com/bjodah/dummypkg/blob/master/revised2-docker-environment-non-egg/Dockerfile#L7

    i.e. the following is added to setup.cfg:

    [easy_install]
    zip_ok = False
    

    Perhaps a word about this in the docs where --pyargs is discussed is in order? (I could try to write something up and submit a PR if you want).

    Just to make things even more complicated there is the issue of zip_ok vs. zip_safe: http://stackoverflow.com/a/34552171/790973

  4. nicoddemus commented on Mar 10, 2016

    @nicoddemus
    nicoddemus
    on Mar 10, 2016
    Member
    More actions

    Cool, thanks for the links. A PR for the docs would be welcome. 😁

  5. nicoddemus
    closed this as completedon Mar 10, 2016
  6. RonnyPfannschmidt
    reopened this on Mar 11, 2016
  7. RonnyPfannschmidt commented on Mar 11, 2016

    @RonnyPfannschmidt
    RonnyPfannschmidt
    on Mar 11, 2016
    Member
    More actions

    We should handle zipped packages

  8. nicoddemus commented on Mar 11, 2016

    @nicoddemus
    nicoddemus
    on Mar 11, 2016
    Member
    More actions

    Agree, but perhaps we should edit the description or, better yet, create a
    new issue and point to this one?

    Em sex, 11 de mar de 2016 07:08, Ronny Pfannschmidt <
    [email protected]> escreveu:

    We should handle zipped packages

    —
    Reply to this email directly or view it on GitHub
    #1445 (comment).

  9. bjodah
    changed the title [-]py.test package discovery does not work under conda[/-] [+]py.test package discovery does not work for zipped packages[/+] on Mar 11, 2016
  10. michaelaye commented on Nov 8, 2016

    @michaelaye
    michaelaye
    on Nov 8, 2016 · Hidden as off-topic
    show commentMore actions
  11. RonnyPfannschmidt commented on Nov 8, 2016

    @RonnyPfannschmidt
    RonnyPfannschmidt
    on Nov 8, 2016 · Hidden as off-topic
    show commentMore actions
  12. michaelaye commented on Nov 8, 2016

    @michaelaye
    michaelaye
    on Nov 8, 2016 · Hidden as off-topic
    show commentMore actions
  13. nicoddemus
    added
    type: enhancementnew feature or API change, should be merged into features branch
    on Jan 29, 2018
  14. sebp
    added a commit that references this issue on Feb 24, 2019

    Apply workaround for py.test --pyargs

    b065ebe
  15. katzdm commented on Jun 21, 2019

    @katzdm
    katzdm
    on Jun 21, 2019
    More actions

    Is this still an open problem? Is it correct to say that pytest can't test a module from a zip file (e.g. PEX, egg, etc) without first extracting the test file?

  16. RonnyPfannschmidt commented on Jun 22, 2019

    @RonnyPfannschmidt
    RonnyPfannschmidt
    on Jun 22, 2019
    Member
    More actions

    Correct

  17. nicoddemus commented on Jun 22, 2019

    @nicoddemus
    nicoddemus
    on Jun 22, 2019
    Member
    More actions

    I'm curious @katzdm, what's your use case for pytest to import a module from a zipped package? To run a test suite against a created PEX file to ensure it was correctly built?

  18. katzdm commented on Jun 24, 2019

    @katzdm
    katzdm
    on Jun 24, 2019
    More actions

    I've been experimenting with an open-source build system that prefers PEX as the format-of-choice for python "executables". Since tests are "executable", the current implementation assembles a PEX consisting of {application code, test files, pytest, third-party dependencies, test-runner-script}, where the test-runner-script does some initial setup before invoking pytest.main().

    I think this model is probably more of an artifact of other design choices, than an endorsement of this as The Best Way to build and run tests. I came across an issue that eventually led me here though, and wanted to make sure I correctly understood the root cause (thanks for the quick reply!)

  19. RonnyPfannschmidt
    changed the title [-]py.test package discovery does not work for zipped packages[/-] [+]--pyargs discovery for zipped packages/unpacked wheels/eggs[/+] on Sep 22, 2021
  20. effigies commented on May 28, 2024

    @effigies
    effigies
    on May 28, 2024
    More actions

    Just to add a specific use case:

    Downstream packages may want to distribute a zipapp including my package, so I want to exercise all of its functionality when zipped. The most straightforward way I can think to do this would be to use PYTHONPACKAGE=$( ls $PWD/dist/mypkg*.whl ) pytest --pyargs mypkg.

    This doesn't currently work, and I can't readily find an alternative approach.

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

    topic: collectionrelated to the collection phasetype: enhancementnew feature or API change, should be merged into features branch

    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.