Question and answer
- Install the required packages by running the command
pip install -r requirements.txtin your terminal.
- Navigate to the directory containing your
main.pyfile. If yourmain.pyis inside theappdirectory, you should be in the same directory as theappfolder. - Run the command
uvicorn app.main:app --reloadin your terminal. This command tells Uvicorn to run your application, which is located in theapp.mainmodule, and the--reloadflag enables hot reloading, which means the server will automatically update whenever you make changes to your code.
After running the command, you should see output indicating that the server is running. You can then access the application by navigating to http://localhost:8000 in your web browser.
- Navigate to the root directory of the project (the same directory as the
appfolder). - Run the command
pytestin your terminal.
This will discover and run all test cases in the tests directory. Make sure you have the pytest package installed. If not, you can install it with pip install pytest.
- Build the Docker images by running the command
docker-compose buildin your terminal. - Start the application by running the command
docker-compose upin your terminal.
After running these commands, you should see output indicating that the application and the MongoDB database are running. You can then access the application by navigating to http://localhost:8000 in your web browser.
To stop the application, press Ctrl+C in your terminal. To remove the containers entirely, run docker-compose down.