+++ /dev/null
-PYTHONPATH=./docs_src
</div>
This command generates a directory `./htmlcov/`, if you open the file `./htmlcov/index.html` in your browser, you can explore interactively the regions of code that are covered by the tests, and notice if there is any region missing.
-
-### Tests in your editor
-
-If you want to use the integrated tests in your editor add `./docs_src` to your `PYTHONPATH` variable.
-
-For example, in VS Code you can create a file `.env` with:
-
-```env
-PYTHONPATH=./docs_src
-```
</div>
该命令生成了一个 `./htmlcov/` 目录,如果你在浏览器中打开 `./htmlcov/index.html` 文件,你可以交互式地浏览被测试所覆盖的代码区块,并注意是否缺少了任何区块。
-
-### 在编辑器中测试
-
-如果你想要在编辑器中运行集成测试,请将 `./docs_src` 加入到你的 `PYTHONPATH` 变量中。
-
-例如,在 VS Code 中你可以创建一个包含以下内容的 `.env` 文件:
-
-```env
-PYTHONPATH=./docs_src
-```
mypy fastapi
black fastapi tests --check
-isort fastapi tests docs_src scripts --check-only
+isort fastapi tests docs_src scripts --check-only
static_dir: Path = Path(os.getcwd()) / "static"
print(static_dir)
static_dir.mkdir(exist_ok=True)
- from extending_openapi.tutorial002 import app
+ from docs_src.extending_openapi.tutorial002 import app
with TestClient(app) as client:
yield client
if test_db.is_file(): # pragma: nocover
test_db.unlink()
# Import while creating the client to create the DB after starting the test session
- from sql_databases.sql_app import main
+ from docs_src.sql_databases.sql_app import main
# Ensure import side effects are re-executed
importlib.reload(main)
if test_db.is_file(): # pragma: nocover
test_db.unlink()
# Import while creating the client to create the DB after starting the test session
- from sql_databases.sql_app import alt_main
+ from docs_src.sql_databases.sql_app import alt_main
# Ensure import side effects are re-executed
importlib.reload(alt_main)
if test_db.is_file(): # pragma: nocover
test_db.unlink()
# Import while creating the client to create the DB after starting the test session
- from sql_databases.sql_app.tests import test_sql_app
+ from docs_src.sql_databases.sql_app.tests import test_sql_app
# Ensure import side effects are re-executed
importlib.reload(test_sql_app)
@pytest.fixture(scope="module")
def client():
# Import while creating the client to create the DB after starting the test session
- from sql_databases_peewee.sql_app.main import app
+ from docs_src.sql_databases_peewee.sql_app.main import app
test_db = Path("./test.db")
with TestClient(app) as c:
+import os
import shutil
from fastapi.testclient import TestClient
def test_main():
+ if os.path.isdir("./static"): # pragma: nocover
+ shutil.rmtree("./static")
+ if os.path.isdir("./templates"): # pragma: nocover
+ shutil.rmtree("./templates")
shutil.copytree("./docs_src/templates/templates/", "./templates")
shutil.copytree("./docs_src/templates/static/", "./static")
- from templates.tutorial001 import app
+ from docs_src.templates.tutorial001 import app
client = TestClient(app)
response = client.get("/items/foo")
-from app_testing.test_main import client, test_read_main
+from docs_src.app_testing.test_main import client, test_read_main
openapi_schema = {
"openapi": "3.0.2",
-from app_testing.tutorial001 import client, test_read_main
+from docs_src.app_testing.tutorial001 import client, test_read_main
openapi_schema = {
"openapi": "3.0.2",
-from app_testing.tutorial002 import test_read_main, test_websocket
+from docs_src.app_testing.tutorial002 import test_read_main, test_websocket
def test_main():
-from app_testing.tutorial003 import test_read_items
+from docs_src.app_testing.tutorial003 import test_read_items
def test_main():
-from dependency_testing.tutorial001 import (
+from docs_src.dependency_testing.tutorial001 import (
app,
client,
test_override_in_items,
import pytest
from fastapi.testclient import TestClient
from fastapi.websockets import WebSocketDisconnect
-from websockets.tutorial001 import app
+
+from docs_src.websockets.tutorial001 import app
client = TestClient(app)
import pytest
from fastapi.testclient import TestClient
from fastapi.websockets import WebSocketDisconnect
-from websockets.tutorial002 import app
+
+from docs_src.websockets.tutorial002 import app
client = TestClient(app)