Skip to content

Commit 9d886a6

Browse files
committed
De-dent a bunch of MockVWS __enter__
Do not .start() the mock twice
1 parent ac4c244 commit 9d886a6

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

src/mock_vws/_requests_mock_server/decorators.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -116,33 +116,33 @@ def __enter__(self) -> Self:
116116
Returns:
117117
``self``.
118118
"""
119-
with Mocker(real_http=self._real_http) as mock:
120-
for vws_route in self._mock_vws_api.routes:
121-
url_pattern = urljoin(
122-
base=self._base_vws_url,
123-
url=f"{vws_route.path_pattern}$",
119+
mock = Mocker(real_http=self._real_http)
120+
for vws_route in self._mock_vws_api.routes:
121+
url_pattern = urljoin(
122+
base=self._base_vws_url,
123+
url=f"{vws_route.path_pattern}$",
124+
)
125+
126+
for vws_http_method in vws_route.http_methods:
127+
mock.register_uri(
128+
method=vws_http_method,
129+
url=re.compile(url_pattern),
130+
text=getattr(self._mock_vws_api, vws_route.route_name),
124131
)
125132

126-
for vws_http_method in vws_route.http_methods:
127-
mock.register_uri(
128-
method=vws_http_method,
129-
url=re.compile(url_pattern),
130-
text=getattr(self._mock_vws_api, vws_route.route_name),
131-
)
132-
133-
for vwq_route in self._mock_vwq_api.routes:
134-
url_pattern = urljoin(
135-
base=self._base_vwq_url,
136-
url=f"{vwq_route.path_pattern}$",
133+
for vwq_route in self._mock_vwq_api.routes:
134+
url_pattern = urljoin(
135+
base=self._base_vwq_url,
136+
url=f"{vwq_route.path_pattern}$",
137+
)
138+
139+
for vwq_http_method in vwq_route.http_methods:
140+
mock.register_uri(
141+
method=vwq_http_method,
142+
url=re.compile(url_pattern),
143+
text=getattr(self._mock_vwq_api, vwq_route.route_name),
137144
)
138145

139-
for vwq_http_method in vwq_route.http_methods:
140-
mock.register_uri(
141-
method=vwq_http_method,
142-
url=re.compile(url_pattern),
143-
text=getattr(self._mock_vwq_api, vwq_route.route_name),
144-
)
145-
146146
self._mock = mock
147147
self._mock.start()
148148

0 commit comments

Comments
 (0)