cant able to run unit test cases
See original GitHub issueFirst Check
- I added a very descriptive title to this issue.
- I used the GitHub search to find a similar issue and didn’t find it.
- I searched the FastAPI documentation, with the integrated search.
- I already searched in Google “How to X in FastAPI” and didn’t find any information.
- I already read and followed all the tutorial in the docs and didn’t find an answer.
- I already checked if it is not related to FastAPI but to Pydantic.
- I already checked if it is not related to FastAPI but to Swagger UI.
- I already checked if it is not related to FastAPI but to ReDoc.
Commit to Help
- I commit to help with one of those options 👆
Example Code
from fastapi.testclient import TestClient
import json
import os
import sys
from ..main import app
client = TestClient(app)
def test_create_vaccine():
data = {"startTime": '3:30', 'endTime':'5:40'}
response = client.post('/vaccine',json.dumps(data))
assert response.status_code == 201
assert response.json()['startTime'] == '3:30'
Description
I am on the tests folder and ran the test cases by using this cmd(python3 testvaccine.py) It throws the below error.
Please let me know if i am missing anything here.
Traceback (most recent call last):
File "testvaccine.py", line 9, in <module>
from ..main import app
ImportError: attempted relative import with no known parent package
Operating System
macOS
Operating System Details
No response
FastAPI Version
0.75.1
Python Version
3.8.2
Additional Context
No response
Issue Analytics
- State:
- Created a year ago
- Comments:7
Top Results From Across the Web
Tests not running in Test Explorer - visual studio
However, the tests are not running when using the Visual Studio test explorer. The Test Explorer is showing all unit tests, but once...
Read more >How To Resolve Issue Of Test Project Not Running The Unit ...
Two of my test projects didn't run the test cases, it was about to start and took some time to run the test...
Read more >Unable to run a single unit test case through Test Explorer
After installing 15.9 of Visual Studio, I have been unable to run a single unit test case without running all the test cases....
Read more >Run unit tests with Test Explorer - Visual Studio (Windows)
To run code coverage for test methods in a solution: Right-click in Test Explorer and select Analyze Code Coverage for Selected tests.
Read more >Unable to run/debug unit tests · Issue #3313 · microsoft/PTVS
All unit tests in the project will refresh and certain ones disappear after everything has been reloaded. Both cases require me to completely...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Pycharm activates the virtual env on startup, while in vsc you have to do it manually. The folder can be visible on both, depending on your platform (Win/Mac/Linux) you have to enable hidden folders/files to be visible. All that being said this isn’t really a FastAPI issue/ As a comment before suggests look into the basic concepts first before working on an API. Look into virtual environments, and how they work. Basically it would be worthwhile to try to get a better grasp at basic python concepts before doing any API work.
As n8sty suggested, just a quick tip after glancing through the test file. Avoid using relative imports.