Skip to content

feat: Support Python subprocesses #409

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ichard26
Copy link

Pytest-socket should be able to block socket calls in Python subprocesses created by tests (e.g., pip's test suite). To hook into new Python subprocesses, we can use a .pth file to run code during Python startup. This is what pytest-cov does to automagically support subprocess coverage tracking.

State is passed to the .pth file via the _PYTEST_SOCKET_SUBPROCESS environment variable with JSON as the encoding format. Some refactoring was necessary to allow for the right pytest-socket state to be easily passed down to the .pth file (w/o recalculating or rerunning the entirety of pytest_socket.py).

Testing-wise, majority of the tests contained in test_socket.py and test_restrict_hosts.py were copied as subprocess tests. While this doesn't cover every single surface, this should be sufficient to ensure the subprocess support is working properly.

Fixes #401.

Pytest-socket should be able to block socket calls in Python
subprocesses created by tests (e.g., pip's test suite). To hook into new
Python subprocesses, we can use a .pth file to run code during Python
startup. This is what pytest-cov does to automagically support
subprocess coverage tracking.

State is passed to the .pth file via the _PYTEST_SOCKET_SUBPROCESS
environment variable with JSON as the encoding format. Some refactoring
was necessary to allow for the right pytest-socket state to be easily
passed down to the .pth file (w/o recalculating or rerunning the entirety
of pytest_socket.py).

Testing-wise, majority of the tests contained in test_socket.py and
test_restrict_hosts.py were copied as subprocess tests. While this
doesn't cover every single surface, this should be sufficient to ensure
the subprocess support is working properly.
Copy link

codeclimate bot commented Mar 10, 2025

Code Climate has analyzed commit f080053 and detected 1 issue on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 1

View more on Code Climate.

@ichard26
Copy link
Author

Actually, I'd like to make some more major changes. Also, I'm going to test this against pip's test suite first.

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.

subprocess support
1 participant