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
I just tried
nose-watch
and it worked fantastic! install the plugin and run the test with the--with-watch
option.Update: :( it does not seem to work well when running tests from django-nose's manage.py helper.
Eventually I opted to use tdaemon, which supports django, although might require a bit of fiddling as well for full fledged projects.
For example here is how I ran it for my django project:
The
--custom-args
was to focus tests to specific app (same as you would dopython manage.py test a_specific_app_to_test
The
-d
argument is to enable debug logging, which prints which file change triggered the run.The
--ignore-dirs
was necessary because my tests wrote to the logs (which in itself is a problem!) andtdaemon
went into an infinite loop.I did this using gulp. Install gulp-shell:
And in the gulpfile.js:
And it runs the tests anytime there are changes saved to any .py or .html files!
You'll need a continuous integration server, something like Jenkins.
You can use Django Supervisor on top of Django. This will avoid the use of a CI tool (which may be useful in any case, this isn't invalidating the other response - maybe just complementary).
I wrote a Gulp task to automatically run
./manage.py test
whenever any specified Python files are changed or removed. You'll need Node for this.First, install Gulp:
Then use the following
gulpfile.js
and make any necessary adjustments:Then simply run
node node_modules/gulp/bin/gulp.js watch
to run the task :)py.test answer (which also works for nose):
Since py.test understands nose, this works for nose too.