OpenAPITools / OpenAPITools/openapi-generator

[BUG] python-fastapi: pytest fails

Open
#10,280 9 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug Server: Python
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

pytest fails as follows:

#16 0.795 =================================== FAILURES ===================================
#16 0.795 _______________________________ test_place_order _______________________________
#16 0.795
#16 0.795 client = <starlette.testclient.TestClient object at 0x7f085de03210>
#16 0.795
#16 0.795 def test_place_order(client: TestClient):
#16 0.795 """Test case for place_order
#16 0.795
#16 0.795 Place an order for a pet
#16 0.795 """
#16 0.795 > body = openapi_server.Order()
#16 0.795 E NameError: name 'openapi_server' is not defined
#16 0.795
#16 0.795 tests/test_store_api.py:69: NameError

openapi-generator version

5.2.1

OpenAPI declaration file content or url

https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml

Generation Details

Run: docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli:v5.2.1 generate -i /local/openapi.yaml -g python-fastapi -o /local

Steps to reproduce

Run: docker-compose up (or docker-compose build --no-cache)

Related issues/PRs

None

Suggest a fix

Remove openapi_server. and add .dict() in the generated test code, for example:

Original:

    body = openapi_server.Order()

Modification:

    body = Order().dict()

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with the documented docker-compose command, then inspect the generated tests/test_store_api.py and its test_place_order entry point. Compare the generated model construction with the python-fastapi output from the petstore.yaml declaration; done means the generated test imports correctly and pytest passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker-compose, fastapi, openapi, python
Domain
api, backend, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.