-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
conversion of exit codes to enum + exposure #5420
conversion of exit codes to enum + exposure #5420
Conversation
c9f7dea
to
94b4ead
Compare
Howdy @RonnyPfannschmidt! Are you back from your hiatus? 😁 |
no, im currently on childcare leave since the rest of the family is sick and in bed, since they finally sleep i picked something easy that still allows me to retain my code-base familiarity |
This comment has been minimized.
This comment has been minimized.
the last value failure is tricky, there is no simple way not to break the api wrt giving full allowance over the exit code anyway |
for now i do a unconditional warning, im wondering if that should be the case or if the code should be silent about it for now in future i'd like to arrive at a stage where pytest return codes are well defined and enumerated |
im not sure where to best document this |
How about in |
Thanks @RonnyPfannschmidt! While the solution is clever, I'm a little concerned to introduce a I've taken one of your earliest commits (b7cd089) and managed to fix the issue locally in xdist with this trivial change: diff --git a/src/xdist/remote.py b/src/xdist/remote.py
index d87ff4c..1643a64 100644
--- a/src/xdist/remote.py
+++ b/src/xdist/remote.py
@@ -41,7 +41,7 @@ class WorkerInteractor(object):
@pytest.hookimpl(hookwrapper=True)
def pytest_sessionfinish(self, exitstatus):
- self.config.workeroutput["exitstatus"] = exitstatus
+ self.config.workeroutput["exitstatus"] = int(exitstatus)
yield
self.sendevent("workerfinished", workeroutput=self.config.workeroutput) So I think we are better off fixing this in pytest-xdist rather than introduce a new confusing public attribute. I volunteer to fix this in pytest-xdist and make a new release. What do you think? |
docs note: there's a |
implementing it the proposed way is a breaking api change, i'd much rather introduce a new name for the new behavior and then deprecate the old before removing it later while at it we also should introduce errro codes where plugins and test-suites can indicate errors within them and forbid free error codes |
The whole purpose of Even if it is a breaking API change, we will be releasing it in
TBH I would rather then keep the old constants and publish them properly as attributes of |
Why closing @RonnyPfannschmidt? I think the change to |
i missunderstood then - but in that case i'd like to prohibit non-declared exit codes in general |
Hmm sorry then, let me try to be clear about my point of view: I think it is OK to introduce the The small xdist problem is trivially fixable and it is not a good example of problems that code out there can encounter caused by this change because xdist is really a special case because of Having said that, if you agree, these changes are required before we can merge:
I'm happy to do 1). What do you think? |
i'll pick the branch up later today, i just noted its on my desktop, and not the work laptop i have with me as im currently somewhere else - git branch sync is such a pain ^^ |
Sounds great. 👍 |
Done: pytest-dev/pytest-xdist#442 👍 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
d660499
to
2bd619e
Compare
i returned back to the state where passing a integer is still valid, but the type is now primaryly the enum, that gives some wiggle room until we deprecate user defined random values for real |
passes with new xdist t seems :) 👍 @nicoddemus |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks!
I think we are only missing docs now:
- Add
ExitCode
toreference.rst
- Link
ExitCode
in the "Possible exit codes" section inusage.rst
changelog/5125.removal.rst
Outdated
@@ -0,0 +1,2 @@ | |||
Introduce the ``pytest.ExitCode`` Enum and make session.exitcode an instance of it. | |||
User defined exit codes are still valid, but consumers need to take the enum into account. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"but consumers need to take the enum into account."
Not clear to me what this means, what consumers would need to do specifically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
users of that api, like the xdist release you just made to support it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh OK, I got confused because I thought the first and second sentence were related, but the "but consumers take the enum into account" phrase was actually referring to the "Introduce the pytestExitCode" phase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about:
``Session.exitcode`` values are now coded in ``pytest.ExitCode``, an ``IntEnum``. This makes the exit code available for consumer code and are more explicit other than just documentation. User defined exit codes are still valid, but should be used with caution.
The team doesn't expect this change to break test suites or plugins in general, except in esoteric/specific scenarios.
**pytest-xdist** users should upgrade to ``1.29.0`` or later, as ``pytest-xdist`` required a compatibility fix because of this change.
(can't use the "suggestion" feature as this spams multiple lines)
class ExitCode(enum.IntEnum): | ||
OK = 0 | ||
TESTS_FAILED = 1 | ||
INTERRUPTED = 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just occurred to me: is there a consensus about how to name the enumerate members? test_failed
, TestsFailed
or TESTS_FAILED
? I've not seen many enums in the wild so I'm not sure. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm all examples in the enum
docs show ALL_CAPS, so I think we are fine. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using PEP8 for constants
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
basically enum members are constants, thus follow the same rules as constants ^^
src/_pytest/main.py
Outdated
|
||
class ExitCode(enum.IntEnum): | ||
""" | ||
encodes the valid exit codes of pytest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also please add a link to usage.rst
. 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@@ -33,6 +33,8 @@ Running ``pytest`` can result in six different exit codes: | |||
:Exit code 4: pytest command line usage error | |||
:Exit code 5: No tests were collected | |||
|
|||
They are repressended by the :class:`_pytest.main.ExitCode` enum. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*represented
INTERRUPTED = 2 | ||
#: an internal error got in the way | ||
INTERNAL_ERROR = 3 | ||
#: pytest was missused |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*misused
INTERNAL_ERROR = 3 | ||
#: pytest was missused | ||
USAGE_ERROR = 4 | ||
#: pytest couldnt find tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*couldn't
return res | ||
|
||
def genitems(self, colitems): | ||
"""Generate all test items from a collection node. | ||
"""Generate all test items from a collection node.src/_pytest/main.py |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
paste error?
yikes, good finds |
Will you fix them? |
i can get around it mid week |
#3144 might also be related? |
fixes #5125