Skip to content

Latest commit

 

History

History
125 lines (87 loc) · 4.16 KB

File metadata and controls

125 lines (87 loc) · 4.16 KB

Local environment

Setup local environment

Clone the repository.

git clone https://github.com/rharris-nitro/pythonExercise1.git

See How To: Git for more info.

Setup pre-commit hooks and install hooks for git repo.

pip install pre-commit
cd pythonExercise1
pre-commit install

See All About Precommit Hooks for more info.

Install Task

If you are using Homebrew, enter this into the command line:

brew install go-task/tap/go-task

For more info, visit the Taskfile website

Install VSCode

Install VSCode from here. After setting up, you should open the folder in VSCode in the directory where the repo is cloned.

Build Docker image and run container using Task

Run App

  • Build and run a container using Task:

    task build
    task up

You should see the output of your Python script:

my-python-app  | [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Testing App

  • Build and run a container using Task:

    task up-test

You should see the output of your pytest test:

my-python-app  | ============================= test session starts ==============================
my-python-app  | platform linux -- Python 3.11.9, pytest-7.4.3, pluggy-1.5.0
my-python-app  | rootdir: /pythonExercise1
my-python-app  | collected 3 items
my-python-app  |
my-python-app  | tests/test_main.py ...                                                   [100%]
my-python-app  |
my-python-app  | ============================== 3 passed in 0.06s ===============================
my-python-app  | Name                 Stmts   Miss  Cover
my-python-app  | ----------------------------------------
my-python-app  | app/__init__.py          0      0   100%
my-python-app  | app/data.py              7      0   100%
my-python-app  | tests/__init__.py        0      0   100%
my-python-app  | tests/test_main.py      12      0   100%
my-python-app  | ----------------------------------------
my-python-app  | TOTAL                   19      0   100%
my-python-app  | Wrote HTML report to htmlcov/index.html

This shows the pytest on the first half, the coverage report on the second half, and the last line shows there is a nicer HTML format at the given folder path if you don't like the CLI report format

For more info about how pyTest works, visit Pytest for Absolute Beginners For more info on coverage.py, go to <coverage-testing.md>

Debugging

Debugging main

To debug the main image in VSCode, run the image using task and set USE_DEBUG to true:

task up USE_DEBUGPY=true

The same can be done for the test image (FYI: this can only debug unit test, not coverage test)

Go to the Run and Debug section in VSCode, make sure the Debugger is on Remote Attach, and press the green play button.

See <debugging.md> for more info