pytest-socket 0.6.0__tar.gz → 0.8.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pytest_socket-0.6.0 → pytest_socket-0.8.0}/PKG-INFO +44 -32
- {pytest_socket-0.6.0 → pytest_socket-0.8.0}/README.md +28 -13
- pytest_socket-0.8.0/pyproject.toml +68 -0
- pytest_socket-0.8.0/src/pytest_socket/__init__.py +368 -0
- pytest_socket-0.8.0/src/pytest_socket/py.typed +0 -0
- pytest_socket-0.8.0/tests/__init__.py +1 -0
- pytest_socket-0.8.0/tests/common.py +14 -0
- pytest_socket-0.8.0/tests/conftest.py +47 -0
- pytest_socket-0.8.0/tests/test_async.py +48 -0
- {pytest_socket-0.6.0 → pytest_socket-0.8.0}/tests/test_combinations.py +25 -34
- pytest_socket-0.8.0/tests/test_dns.py +122 -0
- {pytest_socket-0.6.0 → pytest_socket-0.8.0}/tests/test_doctest.py +4 -6
- {pytest_socket-0.6.0 → pytest_socket-0.8.0}/tests/test_precedence.py +60 -63
- pytest_socket-0.8.0/tests/test_restrict_hosts.py +514 -0
- {pytest_socket-0.6.0 → pytest_socket-0.8.0}/tests/test_socket.py +112 -117
- pytest_socket-0.6.0/.coveragerc +0 -2
- pytest_socket-0.6.0/pyproject.toml +0 -68
- pytest_socket-0.6.0/pytest_socket.py +0 -232
- pytest_socket-0.6.0/setup.py +0 -29
- pytest_socket-0.6.0/tests/conftest.py +0 -11
- pytest_socket-0.6.0/tests/test_async.py +0 -75
- pytest_socket-0.6.0/tests/test_restrict_hosts.py +0 -266
- {pytest_socket-0.6.0 → pytest_socket-0.8.0}/.flake8 +0 -0
- {pytest_socket-0.6.0 → pytest_socket-0.8.0}/LICENSE +0 -0
|
@@ -1,34 +1,32 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: pytest-socket
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.8.0
|
|
4
4
|
Summary: Pytest Plugin to disable socket calls during tests
|
|
5
|
-
Home-page: https://pypi.org/project/pytest-socket/
|
|
6
|
-
License: MIT
|
|
7
5
|
Author: Mike Fiedler
|
|
8
|
-
Author-email: miketheman@gmail.com
|
|
9
|
-
|
|
6
|
+
Author-email: Mike Fiedler <miketheman@gmail.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
10
9
|
Classifier: Development Status :: 4 - Beta
|
|
11
10
|
Classifier: Framework :: Pytest
|
|
12
11
|
Classifier: Intended Audience :: Developers
|
|
13
|
-
Classifier:
|
|
14
|
-
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Topic :: Software Development :: Testing
|
|
15
13
|
Classifier: Programming Language :: Python
|
|
16
|
-
Classifier: Programming Language :: Python :: 3
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.7
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
19
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
20
14
|
Classifier: Programming Language :: Python :: 3.10
|
|
21
15
|
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
-
Classifier: Programming Language :: Python :: 3.
|
|
23
|
-
Classifier: Programming Language :: Python :: 3.
|
|
24
|
-
Classifier: Programming Language :: Python :: 3.
|
|
25
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
26
19
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
27
|
-
Classifier:
|
|
28
|
-
|
|
20
|
+
Classifier: Operating System :: OS Independent
|
|
21
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Dist: pytest>=7.0.0
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Project-URL: Homepage, https://pypi.org/project/pytest-socket/
|
|
26
|
+
Project-URL: Repository, https://github.com/miketheman/pytest-socket
|
|
29
27
|
Project-URL: Bug Tracker, https://github.com/miketheman/pytest-socket/issues
|
|
30
28
|
Project-URL: Change Log, https://github.com/miketheman/pytest-socket/blob/main/CHANGELOG.md
|
|
31
|
-
Project-URL:
|
|
29
|
+
Project-URL: Funding, https://github.com/sponsors/miketheman
|
|
32
30
|
Description-Content-Type: text/markdown
|
|
33
31
|
|
|
34
32
|
# pytest-socket
|
|
@@ -38,7 +36,6 @@ Description-Content-Type: text/markdown
|
|
|
38
36
|
[](https://github.com/miketheman/pytest-socket/actions?query=workflow%3A%22Python+Tests%22)
|
|
39
37
|
[](https://results.pre-commit.ci/latest/github/miketheman/pytest-socket/main)
|
|
40
38
|
[](https://codeclimate.com/github/miketheman/pytest-socket/maintainability)
|
|
41
|
-
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fmiketheman%2Fpytest-socket?ref=badge_shield)
|
|
42
39
|
[](https://github.com/psf/black)
|
|
43
40
|
|
|
44
41
|
A plugin to use with Pytest to disable or restrict `socket` calls during
|
|
@@ -48,11 +45,17 @@ tests to ensure network calls are prevented.
|
|
|
48
45
|
|
|
49
46
|
## Features
|
|
50
47
|
|
|
51
|
-
- Disables all network calls flowing through Python
|
|
48
|
+
- Disables all network calls flowing through Python's `socket` interface,
|
|
49
|
+
including DNS resolution.
|
|
50
|
+
- Restricts connections to an allow-list of hosts, IP addresses, or CIDR
|
|
51
|
+
network ranges.
|
|
52
|
+
- Allows Unix domain sockets selectively, for example when testing async code.
|
|
53
|
+
- Applies globally via CLI flags, or per-test via fixtures and markers.
|
|
52
54
|
|
|
53
55
|
## Requirements
|
|
54
56
|
|
|
55
|
-
- [Pytest](https://github.com/pytest-dev/pytest)
|
|
57
|
+
- [Pytest](https://github.com/pytest-dev/pytest) 7.0 or greater
|
|
58
|
+
- Python 3.10 or greater
|
|
56
59
|
|
|
57
60
|
## Installation
|
|
58
61
|
|
|
@@ -60,14 +63,16 @@ You can install `pytest-socket` via [pip](https://pypi.python.org/pypi/pip/)
|
|
|
60
63
|
from [PyPI](https://pypi.python.org/pypi):
|
|
61
64
|
|
|
62
65
|
```console
|
|
63
|
-
|
|
66
|
+
pip install pytest-socket
|
|
64
67
|
```
|
|
65
68
|
|
|
66
|
-
or add to your `pyproject.toml` for [
|
|
69
|
+
or add to your `pyproject.toml` for [uv](https://docs.astral.sh/uv/):
|
|
67
70
|
|
|
68
|
-
```
|
|
69
|
-
[
|
|
70
|
-
|
|
71
|
+
```toml
|
|
72
|
+
[project.optional-dependencies]
|
|
73
|
+
dev = [
|
|
74
|
+
"pytest-socket",
|
|
75
|
+
]
|
|
71
76
|
```
|
|
72
77
|
|
|
73
78
|
## Usage
|
|
@@ -76,21 +81,21 @@ Run `pytest --disable-socket`, tests should fail on any access to `socket` or
|
|
|
76
81
|
libraries using socket with a `SocketBlockedError`.
|
|
77
82
|
|
|
78
83
|
To add this flag as the default behavior, add this section to your
|
|
79
|
-
[`pytest.ini`](https://docs.pytest.org/en/
|
|
84
|
+
[`pytest.ini`](https://docs.pytest.org/en/stable/reference/customize.html#pytest-ini):
|
|
80
85
|
|
|
81
86
|
```ini
|
|
82
87
|
[pytest]
|
|
83
88
|
addopts = --disable-socket
|
|
84
89
|
```
|
|
85
90
|
|
|
86
|
-
or add this to your [`setup.cfg`](https://docs.pytest.org/en/
|
|
91
|
+
or add this to your [`setup.cfg`](https://docs.pytest.org/en/stable/reference/customize.html#setup-cfg):
|
|
87
92
|
|
|
88
93
|
```ini
|
|
89
94
|
[tool:pytest]
|
|
90
95
|
addopts = --disable-socket
|
|
91
96
|
```
|
|
92
97
|
|
|
93
|
-
or update your [`conftest.py`](https://docs.pytest.org/en/
|
|
98
|
+
or update your [`conftest.py`](https://docs.pytest.org/en/stable/how-to/writing_plugins.html#conftest-py-local-per-directory-plugins) to include:
|
|
94
99
|
|
|
95
100
|
```python
|
|
96
101
|
from pytest_socket import disable_socket
|
|
@@ -99,6 +104,9 @@ def pytest_runtest_setup():
|
|
|
99
104
|
disable_socket()
|
|
100
105
|
```
|
|
101
106
|
|
|
107
|
+
If you exceptionally want to enable socket for one particular execution
|
|
108
|
+
pass `--force-enable-socket`. It takes precedence over `--disable-socket`.
|
|
109
|
+
|
|
102
110
|
To enable Unix sockets during the test run (e.g. for async), add this option:
|
|
103
111
|
|
|
104
112
|
```ini
|
|
@@ -134,6 +142,9 @@ or for whole test run
|
|
|
134
142
|
addopts = --allow-hosts=127.0.0.1,127.0.1.1
|
|
135
143
|
```
|
|
136
144
|
|
|
145
|
+
Entries may be hostnames, IP addresses, or CIDR network ranges such as
|
|
146
|
+
`192.168.0.0/24`.
|
|
147
|
+
|
|
137
148
|
### Frequently Asked Questions
|
|
138
149
|
|
|
139
150
|
Q: Why is network access disabled in some of my tests but not others?
|
|
@@ -160,8 +171,6 @@ Distributed under the terms of the
|
|
|
160
171
|
[MIT](http://opensource.org/licenses/MIT) license, "pytest-socket" is
|
|
161
172
|
free and open source software
|
|
162
173
|
|
|
163
|
-
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fmiketheman%2Fpytest-socket?ref=badge_large)
|
|
164
|
-
|
|
165
174
|
## Issues
|
|
166
175
|
|
|
167
176
|
If you encounter any problems, please [file an issue](https://github.com/miketheman/pytest-socket/issues)
|
|
@@ -180,3 +189,6 @@ This plugin came about due to the efforts by
|
|
|
180
189
|
question](https://stackoverflow.com/a/30064664), then converted into a
|
|
181
190
|
pytest plugin by [\@miketheman](https://github.com/miketheman).
|
|
182
191
|
|
|
192
|
+
## Star History
|
|
193
|
+
|
|
194
|
+
[](https://star-history.com/#miketheman/pytest-socket&Date)
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
[](https://github.com/miketheman/pytest-socket/actions?query=workflow%3A%22Python+Tests%22)
|
|
6
6
|
[](https://results.pre-commit.ci/latest/github/miketheman/pytest-socket/main)
|
|
7
7
|
[](https://codeclimate.com/github/miketheman/pytest-socket/maintainability)
|
|
8
|
-
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fmiketheman%2Fpytest-socket?ref=badge_shield)
|
|
9
8
|
[](https://github.com/psf/black)
|
|
10
9
|
|
|
11
10
|
A plugin to use with Pytest to disable or restrict `socket` calls during
|
|
@@ -15,11 +14,17 @@ tests to ensure network calls are prevented.
|
|
|
15
14
|
|
|
16
15
|
## Features
|
|
17
16
|
|
|
18
|
-
- Disables all network calls flowing through Python
|
|
17
|
+
- Disables all network calls flowing through Python's `socket` interface,
|
|
18
|
+
including DNS resolution.
|
|
19
|
+
- Restricts connections to an allow-list of hosts, IP addresses, or CIDR
|
|
20
|
+
network ranges.
|
|
21
|
+
- Allows Unix domain sockets selectively, for example when testing async code.
|
|
22
|
+
- Applies globally via CLI flags, or per-test via fixtures and markers.
|
|
19
23
|
|
|
20
24
|
## Requirements
|
|
21
25
|
|
|
22
|
-
- [Pytest](https://github.com/pytest-dev/pytest)
|
|
26
|
+
- [Pytest](https://github.com/pytest-dev/pytest) 7.0 or greater
|
|
27
|
+
- Python 3.10 or greater
|
|
23
28
|
|
|
24
29
|
## Installation
|
|
25
30
|
|
|
@@ -27,14 +32,16 @@ You can install `pytest-socket` via [pip](https://pypi.python.org/pypi/pip/)
|
|
|
27
32
|
from [PyPI](https://pypi.python.org/pypi):
|
|
28
33
|
|
|
29
34
|
```console
|
|
30
|
-
|
|
35
|
+
pip install pytest-socket
|
|
31
36
|
```
|
|
32
37
|
|
|
33
|
-
or add to your `pyproject.toml` for [
|
|
38
|
+
or add to your `pyproject.toml` for [uv](https://docs.astral.sh/uv/):
|
|
34
39
|
|
|
35
|
-
```
|
|
36
|
-
[
|
|
37
|
-
|
|
40
|
+
```toml
|
|
41
|
+
[project.optional-dependencies]
|
|
42
|
+
dev = [
|
|
43
|
+
"pytest-socket",
|
|
44
|
+
]
|
|
38
45
|
```
|
|
39
46
|
|
|
40
47
|
## Usage
|
|
@@ -43,21 +50,21 @@ Run `pytest --disable-socket`, tests should fail on any access to `socket` or
|
|
|
43
50
|
libraries using socket with a `SocketBlockedError`.
|
|
44
51
|
|
|
45
52
|
To add this flag as the default behavior, add this section to your
|
|
46
|
-
[`pytest.ini`](https://docs.pytest.org/en/
|
|
53
|
+
[`pytest.ini`](https://docs.pytest.org/en/stable/reference/customize.html#pytest-ini):
|
|
47
54
|
|
|
48
55
|
```ini
|
|
49
56
|
[pytest]
|
|
50
57
|
addopts = --disable-socket
|
|
51
58
|
```
|
|
52
59
|
|
|
53
|
-
or add this to your [`setup.cfg`](https://docs.pytest.org/en/
|
|
60
|
+
or add this to your [`setup.cfg`](https://docs.pytest.org/en/stable/reference/customize.html#setup-cfg):
|
|
54
61
|
|
|
55
62
|
```ini
|
|
56
63
|
[tool:pytest]
|
|
57
64
|
addopts = --disable-socket
|
|
58
65
|
```
|
|
59
66
|
|
|
60
|
-
or update your [`conftest.py`](https://docs.pytest.org/en/
|
|
67
|
+
or update your [`conftest.py`](https://docs.pytest.org/en/stable/how-to/writing_plugins.html#conftest-py-local-per-directory-plugins) to include:
|
|
61
68
|
|
|
62
69
|
```python
|
|
63
70
|
from pytest_socket import disable_socket
|
|
@@ -66,6 +73,9 @@ def pytest_runtest_setup():
|
|
|
66
73
|
disable_socket()
|
|
67
74
|
```
|
|
68
75
|
|
|
76
|
+
If you exceptionally want to enable socket for one particular execution
|
|
77
|
+
pass `--force-enable-socket`. It takes precedence over `--disable-socket`.
|
|
78
|
+
|
|
69
79
|
To enable Unix sockets during the test run (e.g. for async), add this option:
|
|
70
80
|
|
|
71
81
|
```ini
|
|
@@ -101,6 +111,9 @@ or for whole test run
|
|
|
101
111
|
addopts = --allow-hosts=127.0.0.1,127.0.1.1
|
|
102
112
|
```
|
|
103
113
|
|
|
114
|
+
Entries may be hostnames, IP addresses, or CIDR network ranges such as
|
|
115
|
+
`192.168.0.0/24`.
|
|
116
|
+
|
|
104
117
|
### Frequently Asked Questions
|
|
105
118
|
|
|
106
119
|
Q: Why is network access disabled in some of my tests but not others?
|
|
@@ -127,8 +140,6 @@ Distributed under the terms of the
|
|
|
127
140
|
[MIT](http://opensource.org/licenses/MIT) license, "pytest-socket" is
|
|
128
141
|
free and open source software
|
|
129
142
|
|
|
130
|
-
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fmiketheman%2Fpytest-socket?ref=badge_large)
|
|
131
|
-
|
|
132
143
|
## Issues
|
|
133
144
|
|
|
134
145
|
If you encounter any problems, please [file an issue](https://github.com/miketheman/pytest-socket/issues)
|
|
@@ -146,3 +157,7 @@ This plugin came about due to the efforts by
|
|
|
146
157
|
[\@hangtwenty](https://github.com/hangtwenty) solving a [StackOverflow
|
|
147
158
|
question](https://stackoverflow.com/a/30064664), then converted into a
|
|
148
159
|
pytest plugin by [\@miketheman](https://github.com/miketheman).
|
|
160
|
+
|
|
161
|
+
## Star History
|
|
162
|
+
|
|
163
|
+
[](https://star-history.com/#miketheman/pytest-socket&Date)
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "pytest-socket"
|
|
3
|
+
version = "0.8.0"
|
|
4
|
+
description = "Pytest Plugin to disable socket calls during tests"
|
|
5
|
+
authors = [{ name = "Mike Fiedler", email = "miketheman@gmail.com" }]
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
classifiers = [
|
|
10
|
+
"Development Status :: 4 - Beta",
|
|
11
|
+
"Framework :: Pytest",
|
|
12
|
+
"Intended Audience :: Developers",
|
|
13
|
+
"Topic :: Software Development :: Testing",
|
|
14
|
+
"Programming Language :: Python",
|
|
15
|
+
"Programming Language :: Python :: 3.10",
|
|
16
|
+
"Programming Language :: Python :: 3.11",
|
|
17
|
+
"Programming Language :: Python :: 3.12",
|
|
18
|
+
"Programming Language :: Python :: 3.13",
|
|
19
|
+
"Programming Language :: Python :: 3.14",
|
|
20
|
+
"Programming Language :: Python :: Implementation :: CPython",
|
|
21
|
+
"Operating System :: OS Independent",
|
|
22
|
+
"License :: OSI Approved :: MIT License",
|
|
23
|
+
"Typing :: Typed",
|
|
24
|
+
]
|
|
25
|
+
requires-python = ">= 3.10"
|
|
26
|
+
dependencies = ["pytest>=7.0.0"]
|
|
27
|
+
|
|
28
|
+
[dependency-groups]
|
|
29
|
+
dev = [
|
|
30
|
+
"coverage[toml] >= 7.9",
|
|
31
|
+
"httpx >= 0.28.1",
|
|
32
|
+
"mypy >= 1.20",
|
|
33
|
+
"pytest-randomly >= 3.15.0",
|
|
34
|
+
"starlette >= 0.47.1",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[project.urls]
|
|
38
|
+
"Homepage" = "https://pypi.org/project/pytest-socket/"
|
|
39
|
+
"Repository" = "https://github.com/miketheman/pytest-socket"
|
|
40
|
+
"Bug Tracker" = "https://github.com/miketheman/pytest-socket/issues"
|
|
41
|
+
"Change Log" = "https://github.com/miketheman/pytest-socket/blob/main/CHANGELOG.md"
|
|
42
|
+
"Funding" = "https://github.com/sponsors/miketheman"
|
|
43
|
+
|
|
44
|
+
[project.entry-points.pytest11]
|
|
45
|
+
socket = 'pytest_socket'
|
|
46
|
+
|
|
47
|
+
[tool.uv.build-backend]
|
|
48
|
+
source-include = [".flake8", "tests/*"]
|
|
49
|
+
|
|
50
|
+
[tool.coverage.report]
|
|
51
|
+
include = ["src/pytest_socket/*", "tests/*"]
|
|
52
|
+
|
|
53
|
+
[tool.isort]
|
|
54
|
+
known_first_party = ['pytest_socket', 'conftest']
|
|
55
|
+
# https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#profilegcm
|
|
56
|
+
profile = "black"
|
|
57
|
+
|
|
58
|
+
[tool.mypy]
|
|
59
|
+
strict = true
|
|
60
|
+
|
|
61
|
+
[tool.vulture]
|
|
62
|
+
ignore_decorators = ["@pytest.fixture"]
|
|
63
|
+
ignore_names = ["pytest_*"]
|
|
64
|
+
paths = ["src/pytest_socket"]
|
|
65
|
+
|
|
66
|
+
[build-system]
|
|
67
|
+
requires = ["uv_build>=0.7.20,<0.12.0"]
|
|
68
|
+
build-backend = "uv_build"
|