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

pex -c incorrectly alters exit codes #137

Closed
rouge8 opened this issue Jul 27, 2015 · 3 comments
Closed

pex -c incorrectly alters exit codes #137

rouge8 opened this issue Jul 27, 2015 · 3 comments
Labels

Comments

@rouge8
Copy link
Contributor

rouge8 commented Jul 27, 2015

Running pytest from a pex always exits 0 if there are test failures, but not if there are command line argument processing errors.

For example, given this test_fail.py:

assert False

A pytest pex will exit zero:

$ pex --version && pex pytest -c py.test -o pytest.pex && ./pytest.pex test_fail.py ; echo $?
pex 1.0.1
=========================================================================== test session starts ============================================================================
platform darwin -- Python 2.7.10 -- py-1.4.30 -- pytest-2.7.2
rootdir: /Users/rouge8/forks/pex, inifile:
collected 0 items / 1 errors

================================================================================== ERRORS ==================================================================================
______________________________________________________________________ ERROR collecting test_fail.py _______________________________________________________________________
test_fail.py:1: in <module>
    assert False
E   assert False
========================================================================= 1 error in 0.00 seconds ==========================================================================
0

But running py.test in a virtualenv or similar will exit 1.

On the other hand, giving a bad option to py.test will exit non-zero, as expected:

$ pex --version && pex pytest -c py.test -o pytest.pex && ./pytest.pex --bad-option test_fail.py ; echo $?
pex 1.0.1
usage: pytest.pex [options] [file_or_dir] [file_or_dir] [...]
pytest.pex: error: unrecognized arguments: --bad-option
2
@wickman
Copy link
Contributor

wickman commented Jul 29, 2015

I'm able to repro. This is probably a bug with "-c". If you do "pex pytest -m pytest -o pytest.pex" then it works:

mba=2015.07.29.pex137=; pex pytest -m pytest -o pytest.pex
mba=2015.07.29.pex137=; ./pytest.pex test_fail.py
====================================================== test session starts =======================================================
platform darwin -- Python 2.7.9 -- py-1.4.30 -- pytest-2.7.2
rootdir: /Users/wickman/work/2015.07.29.pex137, inifile: 
collected 1 items 

test_fail.py F

============================================================ FAILURES ============================================================
___________________________________________________________ test_fail ____________________________________________________________

    def test_fail():
>     assert False
E     assert False

test_fail.py:2: AssertionError
==================================================== 1 failed in 0.01 seconds ====================================================
mba=2015.07.29.pex137=; echo $?
1

@rouge8
Copy link
Contributor Author

rouge8 commented Jul 30, 2015

Yup, using -m pytest instead of -c py.test works. Thanks!

@wickman wickman added the bug label Aug 4, 2015
@wickman wickman changed the title pex and pytest exit codes pex -c incorrect alters exit codes Aug 12, 2015
@wickman wickman changed the title pex -c incorrect alters exit codes pex -c incorrectly alters exit codes Aug 12, 2015
@rouge8
Copy link
Contributor Author

rouge8 commented Jul 4, 2016

I looked into this a bit this morning:

According to the setuptools docs:

The functions you specify are called with no arguments, and their return value is passed to sys.exit(), so you can return an errorlevel or message to print to stderr

pex currently just calls the entrypoint function but does nothing with the return value. I would guess returning rather than exiting from the entrypoint is uncommon (pex.bin.pex:main calls sys.exit() itself), which is why I only saw this with py.test.

I'm not sure if I'll have time to work on a fix immediately, but hopefully this writeup is helpful for anyone who does.

rouge8 added a commit to rouge8/pex that referenced this issue Jul 6, 2016
rouge8 added a commit to rouge8/pex that referenced this issue Jul 6, 2016
rouge8 added a commit to rouge8/pex that referenced this issue Jul 6, 2016
rouge8 added a commit to rouge8/pex that referenced this issue Jul 6, 2016
Setuptools does not require `console_scripts` entry points to call
`sys.exit()` (or similar) to exit non-zero:

    The functions you specify are called with no arguments, and their
    return value is passed to `sys.exit()`, so you can return an
    errorlevel or message to print to stderr

This patch updates pex to follow the same behavior.

Fixes pex-tool#137.
@kwlzn kwlzn closed this as completed in #280 Jul 7, 2016
kwlzn pushed a commit that referenced this issue Jul 7, 2016
Setuptools does not require `console_scripts` entry points to call
`sys.exit()` (or similar) to exit non-zero:

    The functions you specify are called with no arguments, and their
    return value is passed to `sys.exit()`, so you can return an
    errorlevel or message to print to stderr

This patch updates pex to follow the same behavior.

Fixes #137.
@kwlzn kwlzn mentioned this issue Jul 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants