Skip to content

Commit

Permalink
test: Use JSON serializer for VCR, instead of ignoring ImportWarning
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Apr 6, 2022
1 parent d0f17f4 commit 9676f1c
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
${{ runner.os }}-pip-
- run: pip install .[test]
# pytest-vcr uses pyyaml, which warns on pypy-3.7 https://github.com/yaml/pyyaml/issues/534
- run: pytest -W error -W ignore::ImportWarning --cov jscc --vcr-record=none tests
- run: pytest -W error --cov jscc --vcr-record=none tests
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: coveralls --service=github
94 changes: 58 additions & 36 deletions tests/cassettes/test_http_get_error.yaml
Original file line number Diff line number Diff line change
@@ -1,36 +1,58 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.23.0
method: GET
uri: http://httpbin.org/status/400
response:
body:
string: ''
headers:
Access-Control-Allow-Credentials:
- 'true'
Access-Control-Allow-Origin:
- '*'
Connection:
- keep-alive
Content-Length:
- '0'
Content-Type:
- text/html; charset=utf-8
Date:
- Sun, 15 Mar 2020 20:45:10 GMT
Server:
- gunicorn/19.9.0
status:
code: 400
message: BAD REQUEST
version: 1
{
"version": 1,
"interactions": [
{
"request": {
"method": "GET",
"uri": "http://httpbin.org/status/400",
"body": null,
"headers": {
"User-Agent": [
"python-requests/2.27.1"
],
"Accept-Encoding": [
"gzip, deflate"
],
"Accept": [
"*/*"
],
"Connection": [
"keep-alive"
]
}
},
"response": {
"status": {
"code": 400,
"message": "BAD REQUEST"
},
"headers": {
"Date": [
"Wed, 06 Apr 2022 15:44:05 GMT"
],
"Access-Control-Allow-Credentials": [
"true"
],
"Server": [
"gunicorn/19.9.0"
],
"Connection": [
"keep-alive"
],
"Content-Type": [
"text/html; charset=utf-8"
],
"Content-Length": [
"0"
],
"Access-Control-Allow-Origin": [
"*"
]
},
"body": {
"string": ""
}
}
}
]
}
94 changes: 58 additions & 36 deletions tests/cassettes/test_http_head_error.yaml
Original file line number Diff line number Diff line change
@@ -1,36 +1,58 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.23.0
method: HEAD
uri: http://httpbin.org/status/400
response:
body:
string: ''
headers:
Access-Control-Allow-Credentials:
- 'true'
Access-Control-Allow-Origin:
- '*'
Connection:
- keep-alive
Content-Length:
- '0'
Content-Type:
- text/html; charset=utf-8
Date:
- Sun, 15 Mar 2020 20:45:10 GMT
Server:
- gunicorn/19.9.0
status:
code: 400
message: BAD REQUEST
version: 1
{
"version": 1,
"interactions": [
{
"request": {
"method": "HEAD",
"uri": "http://httpbin.org/status/400",
"body": null,
"headers": {
"User-Agent": [
"python-requests/2.27.1"
],
"Accept-Encoding": [
"gzip, deflate"
],
"Accept": [
"*/*"
],
"Connection": [
"keep-alive"
]
}
},
"response": {
"status": {
"code": 400,
"message": "BAD REQUEST"
},
"headers": {
"Date": [
"Wed, 06 Apr 2022 15:44:04 GMT"
],
"Access-Control-Allow-Credentials": [
"true"
],
"Server": [
"gunicorn/19.9.0"
],
"Connection": [
"keep-alive"
],
"Content-Type": [
"text/html; charset=utf-8"
],
"Content-Length": [
"0"
],
"Access-Control-Allow-Origin": [
"*"
]
},
"body": {
"string": ""
}
}
}
]
}
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import pytest


@pytest.fixture(scope='module')
def vcr_config():
# Avoid ImportWarning from YAML on PyPy 3.7. https://github.com/yaml/pyyaml/issues/534
return {'serializer': 'json'}

0 comments on commit 9676f1c

Please sign in to comment.