Skip to content

Commit a4c4331

Browse files
committed
Detect blocking calls in coroutines using BlockBuster
1 parent e70d0b0 commit a4c4331

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ trio-typing==0.10.0
2828
trustme==1.1.0; python_version < '3.9'
2929
trustme==1.2.0; python_version >= '3.9'
3030
uvicorn==0.32.1
31+
blockbuster==1.5.23

tests/conftest.py

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import pytest
99
import trustme
10+
from blockbuster import blockbuster_ctx
1011
from cryptography.hazmat.backends import default_backend
1112
from cryptography.hazmat.primitives.serialization import (
1213
BestAvailableEncryption,
@@ -31,6 +32,13 @@
3132
}
3233

3334

35+
@pytest.fixture(autouse=True)
36+
def blockbuster():
37+
with blockbuster_ctx() as bb:
38+
bb.functions["os.stat"].can_block_in("/mimetypes.py", "init")
39+
yield bb
40+
41+
3442
@pytest.fixture(scope="function", autouse=True)
3543
def clean_environ():
3644
"""Keeps os.environ clean for every test without having to mock os.environ"""

tests/models/test_whatwg.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
# https://url.spec.whatwg.org/
44

55
import json
6+
from pathlib import Path
67

78
import pytest
89

910
from httpx._urlparse import urlparse
1011

1112
# URL test cases from...
1213
# https://github.com/web-platform-tests/wpt/blob/master/url/resources/urltestdata.json
13-
with open("tests/models/whatwg.json", "r", encoding="utf-8") as input:
14+
whatwg_path = Path(__file__).parent.parent / "models" / "whatwg.json"
15+
with whatwg_path.open("r", encoding="utf-8") as input:
1416
test_cases = json.load(input)
1517
test_cases = [
1618
item

0 commit comments

Comments
 (0)