2.3 KiB
intro_python
Setting up
Let's first initialise a Python environment that is local to this project.
The following commands will create a env/
directory containing a local Python installation.
The second line will then activate it; our terminal will use the local installation:
Commençons par initialiser un environnement Python local au projet.
Les commandes suivantes vont crée un répertoire env/
qui contiendra une installation Python locale.
La deuxième ligne va ensuite l'activer ; notre terminal utilisera alors l'installation locale :
*
python3 -m venv env
source env/bin/activate
We are going to use PDM to package our project. Let's install it with pip:
On va utiliser PDM pour empaqueter notre projet. Installons-le avec pip : *
pip install pdm
We can now run the pdm
command. Let's build our project just to check that every thing is alright:
On peut désormais lancer la commande pdm
. Essayons de build notre programme pour être sûr⋅e que tout va bien :
*
pdm build
student and complete
Python code and tests are written in two files: myfile_student.py
and myfile_complete.py
. The former has holes in it, for the students to complete, while the latter has the full code and test.
In order to execute the tests -- or export the directory to a new repo for the students, one needs to remove the _student
or _complete
part. The exec.sh
scripts does that for you: use ./exec.sh student
to create the student package, ./exec.sh complete
to build the complete package, and ./exec.sh reset
to reset files.
Running the tests
See also the tests for the module, located in test_my_script.py.
Run tests with `pytest test_my_script`:
$ pytest test_my_script.py -vvvv
======================== test session starts ========================
platform linux -- Python 3.11.2, pytest-7.2.1, pluggy-1.0.0+repack -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /home/user/project/scripts/templates
collected 1 item
test_my_script.py::test_add_integers_case0 PASSED [100%]
========================= 1 passed in 0.00s =========================