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

Fix exit code for command line errors #3925

Merged
merged 1 commit into from
Sep 4, 2018

Conversation

crazymerlyn
Copy link
Member

Fixes #3913

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thaks a lot @crazymerlyn!

I'm surprised we don't have any tests for this. Please add a test which calls pytest with the wrong arguments and checks the correct return code. I believe something like this in acceptance_test.py would suffice:

def test_usage_error_code(testdir):
    result = testdir.runpytest('-unknown-option-')
    assert result.ret == EXIT_USAGEERROR

@nicoddemus
Copy link
Member

Oh and I forgot: please target the features branch. Although this is a bug fix, it is still changing the outcome of the pytest command, so we better be safe and release this in 3.8. 👍

@codecov
Copy link

codecov bot commented Sep 3, 2018

Codecov Report

Merging #3925 into features will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##           features    #3925      +/-   ##
============================================
+ Coverage     96.24%   96.24%   +<.01%     
============================================
  Files           108      108              
  Lines         23409    23419      +10     
============================================
+ Hits          22529    22539      +10     
  Misses          880      880
Flag Coverage Δ
#doctesting 31.84% <40%> (+0.06%) ⬆️
#nobyte 93.5% <100%> (-0.01%) ⬇️
#numpy 31.41% <40%> (+0.06%) ⬆️
#pexpect 53.54% <57.14%> (ø) ⬆️
#pluggymaster 95.08% <100%> (+0.02%) ⬆️
#py27 94.61% <100%> (ø) ⬆️
#py34 93.89% <100%> (+0.02%) ⬆️
#py35 93.9% <100%> (+0.02%) ⬆️
#py36 94.82% <100%> (ø) ⬆️
#py37 94.06% <100%> (+0.02%) ⬆️
#trial 34.08% <40%> (+0.06%) ⬆️
#xdist 94.64% <100%> (ø) ⬆️
Impacted Files Coverage Δ
src/_pytest/config/argparsing.py 93.85% <100%> (+0.19%) ⬆️
testing/acceptance_test.py 98.9% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 01df368...b01704c. Read the comment docs.

@crazymerlyn crazymerlyn changed the base branch from master to features September 3, 2018 04:20
@crazymerlyn
Copy link
Member Author

Changelog entry fixed, test added and the pull request now targets the features branch.

@nicoddemus nicoddemus closed this Sep 3, 2018
@nicoddemus nicoddemus reopened this Sep 3, 2018
@nicoddemus
Copy link
Member

Thanks @crazymerlyn! Closing/reopening the PR to restart CI.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 94.064% when pulling b01704c on crazymerlyn:fix-exit-code into 01df368 on pytest-dev:features.

@nicoddemus nicoddemus merged commit 29bfa5e into pytest-dev:features Sep 4, 2018
@crazymerlyn crazymerlyn deleted the fix-exit-code branch September 4, 2018 15:17
@@ -2,8 +2,13 @@
import warnings
import argparse

from gettext import gettext as _
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pytest does not use gettext at all so why add it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, totally missed that. Weird though, shouldn't flake8 catch that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RonnyPfannschmidt The default implementation of error function used it and I didn't want to change anything other than the error code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, it is used:

self.exit(EXIT_USAGEERROR, _("%(prog)s: error: %(message)s\n") % args)

Even though we don't translate pytest messages, I don't mind leaving it in as gettext is already being imported by argparser anyway. But want me to remove it @RonnyPfannschmidt?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crazymerlyn thanks for the additional context
@nicoddemus thanks for the investigation

im a bit thorn between keeping similarity to imported code and limiting code scope, lets keep it as is for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants