-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Add timeout for Testdir.runpytest_subprocess() and Testdir.run() #4078
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
Changes from all commits
96b2ae6
870a93c
fe7050b
d290695
d5e5433
33f0338
dcd635b
0d095fc
900cef6
dd225e1
dcf9eb0
5c38a51
f3a173b
42422a7
8e0e862
ee64f1f
ed5556b
20902de
5ecbb0a
4b36f9a
ccaec8d
48dcc67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Allow specification of timeout for ``Testdir.runpytest_subprocess()`` and ``Testdir.run()``. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| import py.path | ||
| import pytest | ||
| import sys | ||
| import time | ||
| import _pytest.pytester as pytester | ||
| from _pytest.pytester import HookRecorder | ||
| from _pytest.pytester import CwdSnapshot, SysModulesSnapshot, SysPathsSnapshot | ||
|
|
@@ -401,3 +402,32 @@ def test_testdir_subprocess(testdir): | |
| def test_unicode_args(testdir): | ||
| result = testdir.runpytest("-k", u"💩") | ||
| assert result.ret == EXIT_NOTESTSCOLLECTED | ||
|
|
||
|
|
||
| def test_testdir_run_no_timeout(testdir): | ||
| testfile = testdir.makepyfile("def test_no_timeout(): pass") | ||
| assert testdir.runpytest_subprocess(testfile).ret == EXIT_OK | ||
|
|
||
|
|
||
| def test_testdir_run_with_timeout(testdir): | ||
| testfile = testdir.makepyfile("def test_no_timeout(): pass") | ||
|
|
||
| start = time.time() | ||
| result = testdir.runpytest_subprocess(testfile, timeout=120) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @altendky
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately the build failure is gone, likely because it was restarted?! (would be good to copy'n'paste those in the future). (it was for py27-pluggymaster)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :[ Yes, I should have extended that as well. Or, really, made one number calculated from the other to avoid this error in the future. How should I proceed? Push a new commit to the branch? Start a new branch? And :[ again. I did double check that my link to the broken build was for a specific build. I didn't realize that Travis was going to reuse that number and effectively break the link. Lesson learned. sigh Don't restart builds, trigger a new build (empty commit, close/reopen PR, something). |
||
| end = time.time() | ||
| duration = end - start | ||
|
|
||
| assert result.ret == EXIT_OK | ||
| assert duration < 5 | ||
|
|
||
|
|
||
| def test_testdir_run_timeout_expires(testdir): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| testfile = testdir.makepyfile( | ||
| """ | ||
| import time | ||
|
|
||
| def test_timeout(): | ||
| time.sleep(10)""" | ||
| ) | ||
| with pytest.raises(testdir.TimeoutExpired): | ||
| testdir.runpytest_subprocess(testfile, timeout=1) | ||
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.
should this be
timeout=Noneinstead of allowing arbitrary kwargs? I notice they aren't checked so it could potentially allow.run(foo='bar')even whenfooisn't used / would be aTypeErrorotherwiseThere 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.
I'd love to do that, and did do that, but py2. This re-surprises me each time I find it.
https://repl.it/@altendky/pytest-devpytest4078-001
But yes, if we are concerned about extras getting lost I can add some validation. I was maybe being a bit loose with it given elsewhere in the file there's a random
**kwargsthat is (was?) entirely unused.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.
oh, here's keyword-only arguments in python2+3: