A testing framework working with Starlette TestClient.
Project description
LinearTest
A testing framework working with Starlette TestClient.
- Source code: https://github.com/fanyf22/lineartest/
- Documentation: https://fanyf22.github.io/lineartest/
Dependencies
# requried
python>=3.10
starlette>=0.37.2
pydantic>=2.6.4
# recommended
httpx>=0.27.0 # for starlette.testclient
Installing
The package is published on https://pypi.org/project/lineartest.
Use pip
or poetry
to install it.
# pip
pip install lineartest
# poetry
poetry add lineartest
Also, if you are using the LinearClient
feature, which is based on starlette.testclient.TestClient
, you may need to install httpx
:
# pip
pip install httpx
# poetry
poetry add httpx
Features
lineartest.schedule
helps you run tests one-by-one in order, and the tests run later can retrieve the results from the tests run earlier.lineartest.client
helps you log the detail of a request and the response easily.
Example
from pydantic import BaseModel
from starlette.testclient import TestClient
from lineartest import LinearClient, schedule
# import your ASGI app here for testing
...
test_client = TestClient(app)
client = LinearClient(test_client)
# add `test_login` function to schedule
@schedule
def test_login(username, password):
class Response(BaseModel):
success: bool
token: str
# the parameters are the same as `TestClient`
res = client.post('/login', data={
'username': username,
'password': password
}, model=Response) # use `model` parameter to specify a response model
assert res.success
return res.token # the result will be stored by `schedule`
# add `test_resource` function to schedule
@schedule
def test_resource():
# use `schedule.get` to retrieve history result
token = schedule.get(test_login)
class Response(BaseModel):
success: bool
res = client.get('/', headers={
'Authorization': f'Bearer {token}'
}, model=Response)
assert res.success
# run the schedule
# you may pass positional or keyword arguments
schedule.run('username', password='password')
License
This project is licensed under the terms of the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
lineartest-0.1.1.tar.gz
(6.1 kB
view hashes)
Built Distribution
Close
Hashes for lineartest-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4cb20d3c20c7ca77f54648b334adb3f3e26d4f1e274b071a7843f1b65a3df935 |
|
MD5 | 35437797f9aa19d8ac829b1c27ed61fe |
|
BLAKE2b-256 | b31e78627b98363d6f8ae069a074e669642d4516a260492a34b119b75d376ff3 |