pytest-socket 0.7.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.7.0 → pytest_socket-0.8.0}/PKG-INFO +38 -26
- {pytest_socket-0.7.0 → pytest_socket-0.8.0}/README.md +24 -12
- {pytest_socket-0.7.0 → pytest_socket-0.8.0}/pyproject.toml +34 -35
- 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.7.0 → pytest_socket-0.8.0}/tests/common.py +1 -3
- pytest_socket-0.8.0/tests/conftest.py +47 -0
- {pytest_socket-0.7.0 → pytest_socket-0.8.0}/tests/test_async.py +10 -14
- {pytest_socket-0.7.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.7.0 → pytest_socket-0.8.0}/tests/test_doctest.py +4 -6
- {pytest_socket-0.7.0 → pytest_socket-0.8.0}/tests/test_precedence.py +44 -66
- pytest_socket-0.8.0/tests/test_restrict_hosts.py +514 -0
- {pytest_socket-0.7.0 → pytest_socket-0.8.0}/tests/test_socket.py +112 -111
- pytest_socket-0.7.0/pytest_socket.py +0 -260
- pytest_socket-0.7.0/tests/conftest.py +0 -11
- pytest_socket-0.7.0/tests/test_restrict_hosts.py +0 -300
- {pytest_socket-0.7.0 → pytest_socket-0.8.0}/.flake8 +0 -0
- {pytest_socket-0.7.0 → pytest_socket-0.8.0}/LICENSE +0 -0
|
@@ -1,31 +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.8
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
19
14
|
Classifier: Programming Language :: Python :: 3.10
|
|
20
15
|
Classifier: Programming Language :: Python :: 3.11
|
|
21
16
|
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
19
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
23
|
-
Classifier:
|
|
24
|
-
|
|
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
|
|
25
27
|
Project-URL: Bug Tracker, https://github.com/miketheman/pytest-socket/issues
|
|
26
28
|
Project-URL: Change Log, https://github.com/miketheman/pytest-socket/blob/main/CHANGELOG.md
|
|
27
29
|
Project-URL: Funding, https://github.com/sponsors/miketheman
|
|
28
|
-
Project-URL: Repository, https://github.com/miketheman/pytest-socket
|
|
29
30
|
Description-Content-Type: text/markdown
|
|
30
31
|
|
|
31
32
|
# pytest-socket
|
|
@@ -35,7 +36,6 @@ Description-Content-Type: text/markdown
|
|
|
35
36
|
[](https://github.com/miketheman/pytest-socket/actions?query=workflow%3A%22Python+Tests%22)
|
|
36
37
|
[](https://results.pre-commit.ci/latest/github/miketheman/pytest-socket/main)
|
|
37
38
|
[](https://codeclimate.com/github/miketheman/pytest-socket/maintainability)
|
|
38
|
-
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fmiketheman%2Fpytest-socket?ref=badge_shield)
|
|
39
39
|
[](https://github.com/psf/black)
|
|
40
40
|
|
|
41
41
|
A plugin to use with Pytest to disable or restrict `socket` calls during
|
|
@@ -45,11 +45,17 @@ tests to ensure network calls are prevented.
|
|
|
45
45
|
|
|
46
46
|
## Features
|
|
47
47
|
|
|
48
|
-
- 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.
|
|
49
54
|
|
|
50
55
|
## Requirements
|
|
51
56
|
|
|
52
|
-
- [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
|
|
53
59
|
|
|
54
60
|
## Installation
|
|
55
61
|
|
|
@@ -60,11 +66,13 @@ from [PyPI](https://pypi.python.org/pypi):
|
|
|
60
66
|
pip install pytest-socket
|
|
61
67
|
```
|
|
62
68
|
|
|
63
|
-
or add to your `pyproject.toml` for [
|
|
69
|
+
or add to your `pyproject.toml` for [uv](https://docs.astral.sh/uv/):
|
|
64
70
|
|
|
65
|
-
```
|
|
66
|
-
[
|
|
67
|
-
|
|
71
|
+
```toml
|
|
72
|
+
[project.optional-dependencies]
|
|
73
|
+
dev = [
|
|
74
|
+
"pytest-socket",
|
|
75
|
+
]
|
|
68
76
|
```
|
|
69
77
|
|
|
70
78
|
## Usage
|
|
@@ -73,21 +81,21 @@ Run `pytest --disable-socket`, tests should fail on any access to `socket` or
|
|
|
73
81
|
libraries using socket with a `SocketBlockedError`.
|
|
74
82
|
|
|
75
83
|
To add this flag as the default behavior, add this section to your
|
|
76
|
-
[`pytest.ini`](https://docs.pytest.org/en/
|
|
84
|
+
[`pytest.ini`](https://docs.pytest.org/en/stable/reference/customize.html#pytest-ini):
|
|
77
85
|
|
|
78
86
|
```ini
|
|
79
87
|
[pytest]
|
|
80
88
|
addopts = --disable-socket
|
|
81
89
|
```
|
|
82
90
|
|
|
83
|
-
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):
|
|
84
92
|
|
|
85
93
|
```ini
|
|
86
94
|
[tool:pytest]
|
|
87
95
|
addopts = --disable-socket
|
|
88
96
|
```
|
|
89
97
|
|
|
90
|
-
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:
|
|
91
99
|
|
|
92
100
|
```python
|
|
93
101
|
from pytest_socket import disable_socket
|
|
@@ -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
|
|
|
@@ -30,11 +35,13 @@ from [PyPI](https://pypi.python.org/pypi):
|
|
|
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
|
|
@@ -104,6 +111,9 @@ or for whole test run
|
|
|
104
111
|
addopts = --allow-hosts=127.0.0.1,127.0.1.1
|
|
105
112
|
```
|
|
106
113
|
|
|
114
|
+
Entries may be hostnames, IP addresses, or CIDR network ranges such as
|
|
115
|
+
`192.168.0.0/24`.
|
|
116
|
+
|
|
107
117
|
### Frequently Asked Questions
|
|
108
118
|
|
|
109
119
|
Q: Why is network access disabled in some of my tests but not others?
|
|
@@ -130,8 +140,6 @@ Distributed under the terms of the
|
|
|
130
140
|
[MIT](http://opensource.org/licenses/MIT) license, "pytest-socket" is
|
|
131
141
|
free and open source software
|
|
132
142
|
|
|
133
|
-
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fmiketheman%2Fpytest-socket?ref=badge_large)
|
|
134
|
-
|
|
135
143
|
## Issues
|
|
136
144
|
|
|
137
145
|
If you encounter any problems, please [file an issue](https://github.com/miketheman/pytest-socket/issues)
|
|
@@ -149,3 +157,7 @@ This plugin came about due to the efforts by
|
|
|
149
157
|
[\@hangtwenty](https://github.com/hangtwenty) solving a [StackOverflow
|
|
150
158
|
question](https://stackoverflow.com/a/30064664), then converted into a
|
|
151
159
|
pytest plugin by [\@miketheman](https://github.com/miketheman).
|
|
160
|
+
|
|
161
|
+
## Star History
|
|
162
|
+
|
|
163
|
+
[](https://star-history.com/#miketheman/pytest-socket&Date)
|
|
@@ -1,69 +1,68 @@
|
|
|
1
|
-
[
|
|
1
|
+
[project]
|
|
2
2
|
name = "pytest-socket"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.8.0"
|
|
4
4
|
description = "Pytest Plugin to disable socket calls during tests"
|
|
5
|
-
authors = ["Mike Fiedler
|
|
5
|
+
authors = [{ name = "Mike Fiedler", email = "miketheman@gmail.com" }]
|
|
6
6
|
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
7
8
|
readme = "README.md"
|
|
8
|
-
homepage = "https://pypi.org/project/pytest-socket/"
|
|
9
|
-
repository = "https://github.com/miketheman/pytest-socket"
|
|
10
|
-
include = [
|
|
11
|
-
{ path = "LICENSE", format = "sdist" },
|
|
12
|
-
{ path = "README.md", format = "sdist" },
|
|
13
|
-
{ path = "tests", format = "sdist" },
|
|
14
|
-
{ path = ".flake8", format = "sdist" },
|
|
15
|
-
]
|
|
16
9
|
classifiers = [
|
|
17
10
|
"Development Status :: 4 - Beta",
|
|
18
11
|
"Framework :: Pytest",
|
|
19
12
|
"Intended Audience :: Developers",
|
|
20
13
|
"Topic :: Software Development :: Testing",
|
|
21
14
|
"Programming Language :: Python",
|
|
22
|
-
"Programming Language :: Python :: 3.8",
|
|
23
|
-
"Programming Language :: Python :: 3.9",
|
|
24
15
|
"Programming Language :: Python :: 3.10",
|
|
25
16
|
"Programming Language :: Python :: 3.11",
|
|
26
17
|
"Programming Language :: Python :: 3.12",
|
|
18
|
+
"Programming Language :: Python :: 3.13",
|
|
19
|
+
"Programming Language :: Python :: 3.14",
|
|
27
20
|
"Programming Language :: Python :: Implementation :: CPython",
|
|
28
21
|
"Operating System :: OS Independent",
|
|
29
22
|
"License :: OSI Approved :: MIT License",
|
|
23
|
+
"Typing :: Typed",
|
|
30
24
|
]
|
|
25
|
+
requires-python = ">= 3.10"
|
|
26
|
+
dependencies = ["pytest>=7.0.0"]
|
|
31
27
|
|
|
32
|
-
[
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
requests = "^2.26.0"
|
|
41
|
-
starlette = "^0.36.1"
|
|
42
|
-
httpx = "^0.26.0"
|
|
43
|
-
# Waiting for new release. See https://github.com/psf/httpbin/issues/35
|
|
44
|
-
httpbin = { git = "https://github.com/psf/httpbin.git", rev = "1f6e0498" }
|
|
45
|
-
|
|
46
|
-
[tool.poetry.plugins.pytest11]
|
|
47
|
-
socket = 'pytest_socket'
|
|
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
|
+
]
|
|
48
36
|
|
|
49
|
-
[
|
|
37
|
+
[project.urls]
|
|
38
|
+
"Homepage" = "https://pypi.org/project/pytest-socket/"
|
|
39
|
+
"Repository" = "https://github.com/miketheman/pytest-socket"
|
|
50
40
|
"Bug Tracker" = "https://github.com/miketheman/pytest-socket/issues"
|
|
51
41
|
"Change Log" = "https://github.com/miketheman/pytest-socket/blob/main/CHANGELOG.md"
|
|
52
42
|
"Funding" = "https://github.com/sponsors/miketheman"
|
|
53
43
|
|
|
44
|
+
[project.entry-points.pytest11]
|
|
45
|
+
socket = 'pytest_socket'
|
|
46
|
+
|
|
47
|
+
[tool.uv.build-backend]
|
|
48
|
+
source-include = [".flake8", "tests/*"]
|
|
49
|
+
|
|
54
50
|
[tool.coverage.report]
|
|
55
|
-
include = ["
|
|
51
|
+
include = ["src/pytest_socket/*", "tests/*"]
|
|
56
52
|
|
|
57
53
|
[tool.isort]
|
|
58
|
-
known_first_party = ['pytest_socket', 'conftest'
|
|
54
|
+
known_first_party = ['pytest_socket', 'conftest']
|
|
59
55
|
# https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#profilegcm
|
|
60
56
|
profile = "black"
|
|
61
57
|
|
|
58
|
+
[tool.mypy]
|
|
59
|
+
strict = true
|
|
60
|
+
|
|
62
61
|
[tool.vulture]
|
|
63
62
|
ignore_decorators = ["@pytest.fixture"]
|
|
64
63
|
ignore_names = ["pytest_*"]
|
|
65
|
-
paths = ["pytest_socket
|
|
64
|
+
paths = ["src/pytest_socket"]
|
|
66
65
|
|
|
67
66
|
[build-system]
|
|
68
|
-
requires = ["
|
|
69
|
-
build-backend = "
|
|
67
|
+
requires = ["uv_build>=0.7.20,<0.12.0"]
|
|
68
|
+
build-backend = "uv_build"
|