At the moment I am running python manage.py test
every once in a while after I make significant changes in my django project. Is it possible to run those tests automatically whenever I change and save a file in my project? It'll be useful to detect bugs earlier (I know rails has something like this with rspec). I am using nose and django-nose. Thanks in advance.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Django __str__ returned non-string (type NoneType)
- Evil ctypes hack in python
if you use git control code, another way to is use git hook pre-commit
maybe error like
remote: fatal: Not a git repository: '.'
, check this post https://stackoverflow.com/a/4100577/7007942I'm used watchr, something like Watchr
Use entr:
Or, for extra credit, combine it with ack:
If you want it to even find new files as you add them:
I'm a JavaScript developer so I used the tools JS developer have built with Node.js to achieve the same goal in my projects. It is very simple but you also need to install nodeJS to get it working.
I created a file called gruntfile.js in my project root directory:
What it's doing is basically watching any file in that directory that has a py extension and if they changed it execute a shell command which in this case is my python test (you might wanna change it, my test name was main_test.py). In order to run this grunt script you need to install Node.js and after that you will have npm in your global path. after that you need to insall a few node modules as well. All these modules except grunt-cli will be stored in your current folder so make sure you are at the root of your project or what ever folder you put that gruntfile.js in. then run the fallowing commands.
Don't worry about the size, these are very small modules. Now that you have every thing setup you can simply run
grunt
and it will start watching your py files and when you saved them it will run your tests. It may not be best way for running python tests but as I said I'm a JavaScript developer and I think Grunt has provided a very simple way of executing tests even for other languages so I use it.Another Javascript dev here, I've found
nodemon
(https://github.com/remy/nodemon) to work pretty well. By default it watches*.js
files but that's configurable with the--ext
flag. To use it, do:Now, whenever a
*.py
file changes, it'll re-run your command. It even finds new files.I would recommend setting up django-nose and sniffer. It's quite easy to setup and works great. Something along the lines of this scent.py was the only customization I needed. Then you can just run
sniffer -x myapp.tests
.Nose comes with some other goodies that make tests a bit nicer to work with as well.