Repository navigation
Add decorator to run a test in a subprocess. - #8239
Merged
Merged
Conversation
This adds a decorator method to Numba's `TestCase` class which can be used to specify that a test case should be run in a subprocess. This patch further cleans up the test suite to use this decorator where it's reasonable to do so.
stuartarchibald
marked this pull request as ready for review
July 11, 2022 13:56
apmasell
previously approved these changes
Jul 12, 2022
| raise ValueError("Too many args.") | ||
| def wrapper(func): | ||
| def inner(self, *args, **kwargs): | ||
| if os.environ.get("SUBPROC_TEST", None) is None: |
Contributor
There was a problem hiding this comment.
I think this should be "SUBPROC_TEST" in os.environ
Contributor
Author
There was a problem hiding this comment.
Thanks for reviewing. I think it's the inverse condition "SUBPROC_TEST" not in os.environ that's needed, but querying the environment dictionary directly makes sense, added in 15fddea.
apmasell
previously approved these changes
Jul 13, 2022
sklam
reviewed
Jul 13, 2022
| self.assertNotIn('FAIL', status.stderr) | ||
| self.assertNotIn('ERROR', status.stderr) | ||
|
|
||
| def run_test_in_subprocess(*maybefunc, timeout=60, envvars=None): |
Member
There was a problem hiding this comment.
nitpicking... why make maybefunc vararg?
suggestion:
diff --git a/numba/tests/support.py b/numba/tests/support.py
index 0fe2b32ee..14a8a27b2 100644
--- a/numba/tests/support.py
+++ b/numba/tests/support.py
@@ -586,12 +586,12 @@ class TestCase(unittest.TestCase):
self.assertNotIn('FAIL', status.stderr)
self.assertNotIn('ERROR', status.stderr)
- def run_test_in_subprocess(*maybefunc, timeout=60, envvars=None):
+ def run_test_in_subprocess(maybefunc=None, *, timeout=60, envvars=None):
"""Runs the decorated test in a subprocess via invoking numba's test
runner. kwargs timeout and envvars are passed through to
subprocess_test_runner."""
- if len(maybefunc) > 1:
- raise ValueError("Too many args.")
+ # if len(maybefunc) > 1:
+ # raise ValueError("Too many args.")
def wrapper(func):
def inner(self, *args, **kwargs):
if "SUBPROC_TEST" not in os.environ:
@@ -609,9 +609,8 @@ class TestCase(unittest.TestCase):
func(self)
return inner
- if maybefunc and isinstance(maybefunc[0], pytypes.FunctionType):
- func = maybefunc[0]
- return wrapper(func)
+ if isinstance(maybefunc, pytypes.FunctionType):
+ return wrapper(maybefunc)
else:
return wrapper| test_name=func.__name__, | ||
| timeout=timeout, | ||
| envvars=envvars,) | ||
| else: |
Member
There was a problem hiding this comment.
a bit weird to allow SUBPROC_TEST=0 running this branch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds a decorator method to Numba's
TestCaseclass whichcan be used to specify that a test case should be run in a
subprocess. This patch further cleans up the test suite to use
this decorator where it's reasonable to do so.