makePythonTdd.sh

  • Here is the ./makePythonTdd.sh script from how to make a python test driven development environment

    #!/bin/bash
    PROJECT_NAME=$1
    mkdir $PROJECT_NAME
    cd $PROJECT_NAME
    mkdir src
    touch src/$PROJECT_NAME.py
    mkdir tests
    touch tests/__init__.py
    
    echo "import unittest
    
    
    class Test$PROJECT_NAME(unittest.TestCase):
    
        def test_failure(self):
            self.assertFalse(True)
    
    
    # Exceptions Encountered
    # AssertionError
    " > tests/test_$PROJECT_NAME.py
    
    python3 -m venv .venv
    source .venv/bin/activate
    python3 -m pip install --upgrade pip
    echo pytest-watch > requirements.txt
    python3 -m pip install --requirement requirements.txt
    pytest-watch
    
  • use chmod to make the program executable

    chmod +x makePythonTdd.sh
    
  • give a name for the $PROJECT_NAME variable when the program is called to make a Test Driven Development on demand. for example typing this command in the terminal in the folder where makePythonTdd.sh is saved will make a Test Driven Development environment for a project called calculator

    ./makePythonTdd.sh calculator