Skip to content

Commit

Permalink
pytest: remove pytest-retry, use decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
deedy5 committed Apr 17, 2024
1 parent 52853ed commit a4d4f66
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
6 changes: 0 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,7 @@ dependencies = []
[project.optional-dependencies]
dev = [
"pytest>=8.1.1",
"pytest-retry>=1.6.2",
]

[tool.maturin]
features = ["pyo3/extension-module"]

[tool.pytest.ini_options]
retries = 3
retry_delay = 0.5
cumulative_timing = false
24 changes: 22 additions & 2 deletions tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
import json
from time import sleep
from urllib.parse import parse_qs

from pyreqwest_impersonate import Client

import pytest

from pyreqwest_impersonate import Client
def retry(max_retries=3, delay=1):
def decorator(func):
def wrapper(*args, **kwargs):
for attempt in range(max_retries):
try:
return func(*args, **kwargs)
except Exception as e:
if attempt < max_retries - 1:
sleep(delay)
continue
else:
raise e

return wrapper

return decorator

@retry()
def test_client_init_params():
auth = ("user", "password")
headers = {"X-Test": "test"}
Expand All @@ -20,6 +36,7 @@ def test_client_init_params():
assert json_data["args"] == {"x": "aaa", "y": "bbb"}


@retry()
def test_client_get():
auth_bearer = "bearerXXXXXXXXXXXXXXXXXXXX"
headers = {"X-Test": "test"}
Expand All @@ -38,6 +55,7 @@ def test_client_get():
assert json_data["args"] == {"x": "aaa", "y": "bbb"}


@retry()
def test_client_post_content():
auth = ("user", "password")
headers = {"X-Test": "test"}
Expand All @@ -59,6 +77,7 @@ def test_client_post_content():
assert json_data["data"] == "test content"


@retry()
def test_client_post_data():
auth_bearer = "bearerXXXXXXXXXXXXXXXXXXXX"
headers = {"X-Test": "test"}
Expand All @@ -81,6 +100,7 @@ def test_client_post_data():
assert received_data_dict == {"key1": ["value1"], "key2": ["value2"]}


@retry()
def test_client_get_impersonate():
client = Client(impersonate="chrome_123", verify=False)
response = client.get("https://tls.peet.ws/api/all")
Expand Down

0 comments on commit a4d4f66

Please sign in to comment.