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 src
     5mv main.py 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 add --requirement requirements.txt
    25uv run pytest-watcher . --now
    
     1uv init more_magic
     2cd more_magic
     3mkdir src
     4Move-Item "main.py" "src/more_magic.py"
     5mkdir tests
     6New-Item tests/__init__.py
     7
     8"import unittest
     9
    10
    11class TestMoreMagic(unittest.TestCase):
    12
    13    def test_failure(self):
    14        self.assertFalse(True)
    15
    16
    17# Exceptions seen
    18# AssertionError
    19" | Out-File "tests/test_more_magic.py" -Encoding UTF8
    20
    21"pytest" | Out-File requirements.txt -Encoding UTF8
    22"pytest-watcher" >> requirements.txt
    23uv add --requirement requirements.txt
    24uv run pytest-watcher . --now
    
  • change more_magic to the name of your Project and when the program_ is called to make a `Test Driven Development`_ any time you want

  • type this in the terminal_ to run the program_

    ./makePythonTdd.sh
    
    .\makePythonTdd.ps1
    

makePythonTdd with variables


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_NAME as the name if you do not give a name

  • make the class name in CapWords format

  • open the test file_ and source file_ in your editor

code src/$PROJECT_NAME.py and code tests/test_$PROJECT_NAME.py work with `Visual Studio Code`_ you can change code to use the command for any `Integrated Development Environment (IDE)`_ you like