You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This example in https://github.com/snok/drf-openapi-tester isn't flagged with a TC100 when it should be. The Response annotation will otherwise lead to a runtime error.
fromtypingimportTYPE_CHECKINGfromdjango.urlsimportreversefromrest_framework.testimportAPITestCasefromopenapi_testerimportSchemaTesterfromtests.utilsimportTEST_ROOTifTYPE_CHECKING:
fromrest_framework.responseimportResponseschema_tester=SchemaTester(schema_file_path=str(TEST_ROOT) +"/schemas/sample-schemas/content_types.yaml")
classBaseAPITestCase(APITestCase):
"""Base test class for api views including schema validation"""@staticmethoddefassertResponse(response: Response, **kwargs) ->None:
"""helper to run validate_response and pass kwargs to it"""schema_tester.validate_response(response=response, **kwargs)
classPetsAPITests(BaseAPITestCase):
deftest_get_pet_by_id(self):
response=self.client.get(
reverse(
"get-pet",
kwargs={
"petId": 1,
},
),
content_type="application/vnd.api+json",
)
assertresponse.status_code==200self.assertResponse(response)
The text was updated successfully, but these errors were encountered:
Looks like the error is actually caught by the plugin, but is not emitted.
❯ flake8 test.py -v
flake8.checker MainProcess 139 INFO Making checkers
self.options.enable_extensions=None
flake8.type_checking MainProcess 140 INFO Optional warning TC100 Add 'from __future__ import annotations' import not present in selected warnings: ('TC', 'PL', 'C90', 'F', 'E', 'W'). Not running it at all.
self.options.enable_extensions=None
flake8.type_checking MainProcess 140 INFO Optional warning TC200 Annotation 'Response' needs to be made into a string literal not present in selected warnings: ('TC', 'PL', 'C90', 'F', 'E', 'W'). Not running it at all.
flake8.main.application MainProcess 147 INFO Finished running
flake8.main.application MainProcess 147 INFO Reporting errors
flake8.main.application MainProcess 148 INFO Found a total of 0 violations and reported 0
Running it with --select TC100 gives the expected result 🤔
This example in https://github.com/snok/drf-openapi-tester isn't flagged with a TC100 when it should be. The
Response
annotation will otherwise lead to a runtime error.The text was updated successfully, but these errors were encountered: