makePythonTdd
makePythonTdd with no variables
Here is the program from how to make a Python Test Driven Development environment automatically
1#!/bin/bash 2uv init more_magic 3cd more_magic 4mkdir tests 5touch tests/__init__.py 6 7echo "import unittest 8 9 10class TestMoreMagic(unittest.TestCase): 11 12 def test_failure(self): 13 self.assertFalse(True) 14 15 16# Exceptions seen 17# AssertionError 18" > tests/test_more_magic.py 19 20echo "pytest" > requirements.txt 21echo "pytest-watcher" >> requirements.txt 22uv add --requirement requirements.txt 23uv run pytest-watcher . --now1uv init more_magic 2cd more_magic 3mkdir tests 4New-Item tests/__init__.py 5 6"import unittest 7 8 9class TestMoreMagic(unittest.TestCase): 10 11 def test_failure(self): 12 self.assertFalse(True) 13 14 15# Exceptions seen 16# AssertionError 17" | Out-File "tests/test_more_magic.py" -Encoding UTF8 18 19"pytest" | Out-File requirements.txt -Encoding UTF8 20"pytest-watcher" >> requirements.txt 21uv add --requirement requirements.txt 22uv run pytest-watcher . --nowchange
more_magicto the name of your Projecttype this in the terminal to run the program to make a Test Driven Development any time you want
./makePythonTdd.sh.\makePythonTdd.ps1
makePythonTdd with variables
Here is the program from how to make a Python Test Driven Development environment automatically with variables
1#!/bin/bash 2NAME_OF_THE_PROJECT=$1 3uv init $NAME_OF_THE_PROJECT 4cd $NAME_OF_THE_PROJECT 5mkdir tests 6touch tests/__init__.py 7 8echo "import unittest 9 10 11class Test$NAME_OF_THE_PROJECT(unittest.TestCase): 12 13 def test_failure(self): 14 self.assertFalse(True) 15 16 17# Exceptions seen 18# AssertionError 19" > tests/test_$NAME_OF_THE_PROJECT.py 20 21echo "pytest" > requirements.txt 22echo "pytest-watcher" >> requirements.txt 23uv add --requirement requirements.txt 24uv run pytest-watcher . --now1$NAME_OF_THE_PROJECT=$args[0] 2uv init $NAME_OF_THE_PROJECT 3cd $NAME_OF_THE_PROJECT 4mkdir tests 5New-Item tests/__init__.py 6 7"import unittest 8 9 10class Test$($NAME_OF_THE_PROJECT)(unittest.TestCase): 11 12 def test_failure(self): 13 self.assertFalse(True) 14 15 16# Exceptions seen 17# AssertionError 18" | Out-File "tests/test_$NAME_OF_THE_PROJECT.py" -Encoding UTF8 19 20"pytest" | Out-File requirements.txt -Encoding UTF8 21"pytest-watcher" >> requirements.txt 22uv add --requirement requirements.txt 23uv run pytest-watcher . --nowgive a name for the
NAME_OF_THE_PROJECTvariable 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 where the program is saved makes a Test Driven Development environment for a project with the name person./makePythonTdd.sh person.\makePythonTdd.ps1 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
NAME_OF_THE_PROJECTas the name if you do not give a namemake the class name in CapWords format
1#!/bin/bash 2if [ -z "$1" ] ; then 3 NAME_OF_THE_PROJECT="NAME_OF_THE_PROJECT" 4else 5 NAME_OF_THE_PROJECT=$1 6fi 7 8# Split on underscores and convert each word to Title Case, 9# then join with no separator 10IFS='_' read -r -a words <<< "$NAME_OF_THE_PROJECT" 11IFS='' 12CLASS_NAME="${words[*]^}" 13 14uv init $NAME_OF_THE_PROJECT 15cd $NAME_OF_THE_PROJECT 16mkdir tests 17touch tests/__init__.py 18 19echo "import unittest 20 21 22class Test$CLASS_NAME(unittest.TestCase): 23 24 def test_failure(self): 25 self.assertFalse(True) 26 27 28# Exceptions seen 29# AssertionError 30" > tests/test_$NAME_OF_THE_PROJECT.py 31 32echo "pytest" > requirements.txt 33echo "pytest-watcher" >> requirements.txt 34uv add --requirement requirements.txt 35uv run pytest-watcher . --now1param( 2 [string]$NAME_OF_THE_PROJECT = "NAME_OF_THE_PROJECT" 3) 4 5# Split on underscores and convert each word to Title Case, 6# then join with no separator 7$CLASS_NAME = ($NAME_OF_THE_PROJECT -split '_') | 8 ForEach-Object { (Get-Culture).TextInfo.ToTitleCase($_.ToLower()) } | 9 Join-String -Separator '' 10 11$NAME_OF_THE_PROJECT=$args[0] 12uv init $NAME_OF_THE_PROJECT 13cd $NAME_OF_THE_PROJECT 14mkdir tests 15New-Item tests/__init__.py 16 17"import unittest 18 19 20class Test$($CLASS_NAME)(unittest.TestCase): 21 22 def test_failure(self): 23 self.assertFalse(True) 24 25 26# Exceptions seen 27# AssertionError 28" | Out-File "tests/test_$NAME_OF_THE_PROJECT.py" -Encoding UTF8 29 30"pytest" | Out-File requirements.txt -Encoding UTF8 31"pytest-watcher" >> Out-File requirements.txt 32uv add --requirement requirements.txt 33uv run pytest-watcher . --now