Python FastApi Project with VisualCode, testing and debug

Sebastian Velez Zuluaga
3 min readJun 29, 2022

In this topic I would like to show you have to use Visual Code to create project on Python 3.9, with environment variables, debug and unittest.

  1. The environment variables are good if you need transfer the python project maybe to other PC with different S.O
  2. The Debug is an amazing tool that help you, check every step or line from you code.
  3. The unit test help you to change your code for new features and be sure that the old functions still works.
  4. FastApi is a framework that help you to create apis very fast.

https://fastapi.tiangolo.com

So lets do it.

  1. Create folder.
  2. Open folder en VSCODE.
  3. Open you terminal, be sure that the path is the folder that you will use.
python3 -m venv .env

4. Check version of python and pip.

python3 --versionpip3 --version

5. Create simple file main.py with one line

print("hello world")

6 . On you terminar copy and see the result Hello World

python3 main.py
>>>
Hello world

7. install next extension:

Name: Python
Id: ms-python.python
Description: IntelliSense (Pylance), Linting, Debugging (multi-threaded, remote), Jupyter Notebooks, code formatting, refactoring, unit tests, and more.
Version: 2022.8.0
Publisher: Microsoft
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-python.python

8. Install FastAPi, open you terminal

pip3 install “fastapi[all]”

8. on main.py file paste

from fastapi import FastAPIapp = FastAPI()@app.get(“/”)
async def root():
return {“message”: “Hello World”}

9.Create a debug file from python-fast-api. Check in the root path that a new folder is created with one file inside it.

10. Run the debug and the result will be:

11. Configure the unit test. be sure that the icon is in VScode

12. Create folder and file.

import unittest
class test_main(unittest.TestCase): def test_main(self):
print("ready")
if __name__ == '__main__':
unittest.main()

13. configure the unittest for python. Select folder and the path of the files.

Happy TESTING, DEBUGGING AND CODING !!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response