mirror of https://github.com/tiangolo/fastapi.git
Add check for ciruclar imports + test
This commit is contained in:
parent
1fc586c3a5
commit
111de89957
|
|
@ -1333,6 +1333,7 @@ class APIRouter(routing.Router):
|
|||
app.include_router(internal_router)
|
||||
```
|
||||
"""
|
||||
assert self is not router, "Cannot include router into itself"
|
||||
if prefix:
|
||||
assert prefix.startswith("/"), "A path prefix must start with '/'"
|
||||
assert not prefix.endswith("/"), (
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
import pytest
|
||||
from fastapi import APIRouter, FastAPI
|
||||
|
||||
|
||||
def test_router_circular_import():
|
||||
app = FastAPI()
|
||||
router = APIRouter()
|
||||
|
||||
app.include_router(router)
|
||||
with pytest.raises(AssertionError, match="Router cannot be the same as parent"):
|
||||
router.include_router(router)
|
||||
Loading…
Reference in New Issue