Repository used for interactive pytest training at the Minor Planet Center. Inside this repository is a simple Flask web application that displays the output from functions you all will implement (and test!). The concept is a random integer will be passed into a premade function with your name on it, and you implement code to do something to the number, and return the result. Below are the steps to follow for this training.
- Create Github accounts, and get everyone added to this repository
- (optional) Set up github ssh keys
- Unit Test Lecture
- Interactive pytest exercise (using this repo)
- Work together to create a test for some operational code
-
Clone the repository
git clone https://github.com/Smithsonian/mpc-pytest-training.git
or if you have ssh keys set up:
git clone git@github.com:Smithsonian/mpc-pytest-training.git
-
Go into the new repo
cd mpc-pytest-training
-
Create a branch and switch to it
git checkout -b name_of_branch
-
Install the mpc_training package (with the -e edit flag)
pip install -e .
-
Run pytest and ensure the tests pass
pytest
-
Go to the
flask_app
directory and run flask. Check that the website shows upcd flask_app flask run
view at
http://127.0.0.1:5000/
-
Open the mpc_training/team.py file, and find the function with your name on it.
-
Pick your favorite mathematical operation (see Chris' sqrt example), but don't implement it quite yet. Just put a comment in the function to convey your goal. We will come back here once we write a test.
-
Create a new python file in the tests directory called "test_yourname.py", feel free to copy and rename test_chris.py. Remember - pytest automatically finds files prefixed with "test_".
-
Write a test to check your function's output, and run it to ensure it fails :)
-
Now go back to mpc_training/team.py and implement your function, and re-run your unit test until it passes.
-
Now test your function manually by restarting flask ("ctrl-c", "flask run"), and refreshing the localhost page which should still be up in your browser. Make sure you see your output, and you are happy with it.
-
Add new files to git, Commit and Push your code
git add . git commit -m "Implemented function for your_name, and also a correponding unit test" git push --set-upstream origin
-
Check if your branch passes the tests running in Github Actions
-
Open a new pull request for your branch by clicking the green "New Pull Request" button
-
You are done! Chris and N will be reviewing the pull requests and merging them.