Open arpanpreneur opened 2 months ago
I too am getting a similar error, however, I have an entire test_x.py
script that uses Django's default test Client because it's easier to work with the request's session object, whereas all other test scripts use Django Ninja's TestClient.
Interestingly, when I run the entire test suite, I get the error ninja.errors.ConfigError: Router@'/basket/' has already been attached to API NinjaAPI:1.0.0
, but when I invoke pytest path/to/test_x.py
in isolation, it passes.
Versions:
@vitalik Would it be possible for you to take a look into it? Our team is really enjoying Ninja-API, if this could be fixed, our test suite would be even simpler. Currently we are having to write integration test for each API.
If you could even confirm the root cause of this issue, I can help fixing it by submitting a PR.
@arpanpreneur
sometimes this error means some exceptions during import (or circular imports)
you can try skip check with setting NINJA_SKIP_REGISTRY=on
enviroment
see example here how it's done in django ninja test suites
or try with
NINJA_SKIP_REGISTRY=on pytest
Describe the bug I have the following pytest tests, running in the same order as below. The first one uses the NinjaTestClient. Once this
client1.get("/whoami", user=simple_user)
is executed, the next test using Django Test Client fails with the exceptionRouter@'/access-control/' has already been attached to API NinjaAPI:1.0.0
. The stack trace is also pasted below.Versions (please complete the following information):