One of the good things of being exposed to different technologies is that you can get good things/methodologies from one field and apply them to other fields.
One such thing is automating tests running. Normally if you work on a Django (Python?) project you:
- manually write code
- manually write tests
- manually run tests (go to 1 or 2 if tests fail, allways happens to me)
Automating first 2 is a bit problematic (for now) but 3rd one seems like a perfect canditate for that.
Simple way of automating tests running
If you want to get started fast then one option is to:
- Install Nodemon
- Instead of running manually
nodemon --ext '.py' --exec "./manage.py test"once
Then everytime you’ll change a
.py file in you project, tests will rerun automatically. If you want more control over files watching then Nodemon has options for watching only specific file extensions, files, folders or ignoring things.
Advanced way of automating tests running
Say you have a really big project and running all tests takes lots of time, or you want to run only tests affected by file changes, then you can create a recipe like following:
- Name and place your tests file in such a way that it is possible to programatically detect which test file covers a given code file (e.g. views/home.py is tested by tests/views__home.py)
- Create a file watcher (say using Gulp)
- When a test file changes - run only that test file
- When a code file changes:
- If it is possible to detect which test file matches given changed file (see 1) then run only that test file
- Otherwise run all tests (or none)