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 bug with timeout counting #180

Merged
merged 2 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ jobs:
nox -s tests-${{ matrix.python-version }}
env:
PLATFORM: ${{ matrix.platform }}
- name: Update coverage
if: matrix.python-version != 'pypy3.8'
uses: codecov/codecov-action@v3
- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}


mypy:
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ pytest-subprocess
:target: https://pypi.org/project/pytest-subprocess
:alt: Python versions

.. image:: https://codecov.io/gh/aklajnert/pytest-subprocess/branch/master/graph/badge.svg?token=JAU1cGoYL8
:target: https://codecov.io/gh/aklajnert/pytest-subprocess
.. image:: https://codecov.io/github/aklajnert/pytest-subprocess/graph/badge.svg?token=JAU1cGoYL8
:target: https://codecov.io/github/aklajnert/pytest-subprocess

.. image:: https://readthedocs.org/projects/pytest-subprocess/badge/?version=latest
:target: https://pytest-subprocess.readthedocs.io/en/latest/?badge=latest
Expand Down
7 changes: 6 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
def tests(session):
session.install(".[test]")
session.run(
"coverage", "run", "-m", "pytest", "--timeout=300", "-v", *session.posargs
"pytest",
"--cov",
"--junitxml=junit.xml",
"-o",
"junit_family=legacy",
*session.posargs
)


Expand Down
5 changes: 3 additions & 2 deletions pytest_subprocess/fake_popen.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ def poll(self) -> Optional[int]:
return self.returncode

def wait(self, timeout: Optional[float] = None) -> int:
if timeout and self._wait_timeout and timeout < self._wait_timeout:
if timeout and self._wait_timeout:
self._wait_timeout -= timeout
raise subprocess.TimeoutExpired(self.args, timeout)
if timeout < self._wait_timeout:
raise subprocess.TimeoutExpired(self.args, timeout)
self._finalize_thread(timeout)
if self.returncode is None:
raise exceptions.PluginInternalError
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def read(fname):
extras_require={
"test": [
"pytest>=4.0",
"coverage",
"pytest-cov",
"docutils>=0.12",
"Pygments>=2.0",
"pytest-rerunfailures",
Expand Down
10 changes: 5 additions & 5 deletions tests/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,15 +482,15 @@ def test_ambiguous_input(fp, fake):
@pytest.mark.parametrize("fake", [False, True])
def test_multiple_wait(fp, fake):
"""
Wait multiple times for 0.2 seconds with process lasting for 0.5.
Third wait shall is a bit longer and will not raise an exception,
Wait multiple times for 0.2 seconds with process lasting for 0.7.
Third wait shall be a bit longer and will not raise an exception,
due to exceeding the subprocess runtime.
"""
fp.allow_unregistered(not fake)
if fake:
fp.register(
[PYTHON, "example_script.py", "wait"],
wait=0.5,
wait=0.7,
)

process = subprocess.Popen(
Expand All @@ -500,9 +500,9 @@ def test_multiple_wait(fp, fake):
process.wait(timeout=0.2)

with pytest.raises(subprocess.TimeoutExpired):
process.wait(timeout=0.1)
process.wait(timeout=0.2)

process.wait(0.4)
process.wait(0.6)

assert process.returncode == 0

Expand Down
Loading