makePythonTdd.sh
makePythonTdd.sh with no variables
Here is the
makePythonTdd.shprogram from how to make a python test driven development environment1#!/bin/bash 2mkdir more_magic 3cd more_magic 4mkdir src 5touch src/more_magic.py 6mkdir tests 7touch tests/__init__.py 8 9echo "import unittest 10 11 12class TestMoreMagic(unittest.TestCase): 13 14 def test_failure(self): 15 self.assertFalse(True) 16 17 18# Exceptions seen 19# AssertionError 20" > tests/test_more_magic.py 21 22echo "pytest" > requirements.txt 23echo "pytest-watcher" >> requirements.txt 24uv init 25rm main.py 26uv add --requirement requirements.txt 27uv run pytest-watcher . --nowuse
chmodto make the program executablechmod +x makePythonTdd.shgive a name for the
PROJECT_NAMEvariable when the program is called to make a Test Driven Development any time you want. For example typing this command in the terminal in the folder wheremakePythonTdd.shis saved makes a Test Driven Development environment for a project with the name person./makePythonTdd.sh person
makePythonTdd.sh with variables
Here is the
makePythonTdd.shprogram from how to make a python test driven development environment1#!/bin/bash 2PROJECT_NAME=$1 3mkdir $PROJECT_NAME 4cd $PROJECT_NAME 5mkdir src 6touch src/$PROJECT_NAME.py 7mkdir tests 8touch tests/__init__.py 9 10echo "import unittest 11 12 13class Test$PROJECT_NAME(unittest.TestCase): 14 15 def test_failure(self): 16 self.assertFalse(True) 17 18 19# Exceptions seen 20# AssertionError 21" > tests/test_$PROJECT_NAME.py 22 23python3 -m venv .venv 24source .venv/bin/activate 25python3 -m pip install --upgrade pip 26echo "pytest-watcher" > requirements.txt 27python3 -m pip install --requirement requirements.txt 28pytest-watcheruse
chmodto make the program executablechmod +x makePythonTdd.shgive a name for the
PROJECT_NAMEvariable when the program is called to make a Test Driven Development any time you want. For example typing this command in the terminal in the folder wheremakePythonTdd.shis saved makes a Test Driven Development environment for a project with the name person./makePythonTdd.sh person
BONUS: makePythonTdd.sh Pro
Since you are the adventurous type and made it this deep in the book, I have added extra lines that
make the project with
PROJECT_NAMEas the name if you do not give a namemake the class name in CapWords format
1#!/bin/bash
2if [ -z "$1" ] ; then
3 PROJECT_NAME="PROJECT_NAME"
4else
5 PROJECT_NAME=$1
6fi
7
8IFS='_' read -r -a words <<< "$PROJECT_NAME"
9IFS=''
10CLASS_NAME="${words[*]^}"
11
12mkdir -p $PROJECT_NAME/{src,tests}
13cd $PROJECT_NAME
14touch src/$PROJECT_NAME.py tests/__init__.py
15
16echo "import unittest
17
18
19class Test$CLASS_NAME(unittest.TestCase):
20
21 def test_failure(self):
22 self.assertFalse(True)
23
24
25# Exceptions seen
26# AssertionError
27" > tests/test_$PROJECT_NAME.py
28
29code src/$PROJECT_NAME.py
30code tests/test_$PROJECT_NAME.py
31
32echo "pytest" > requirements.txt
33echo "pytest-watcher" >> requirements.txt
34uv init
35rm main.py
36uv add --requirement requirements.txt
37uv run pytest-watcher . --now
this works with Visual Studio Code you can change it to use the command for any Integrated Development Environment (IDE) you like