How to automatically run tests when there's any change in my project (Django)?

后端 未结 14 1921
有刺的猬
有刺的猬 2020-12-23 19:45

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

14条回答
  •  青春惊慌失措
    2020-12-23 20:14

    I've found the easiest way is to use gulp as recommended by this post. Note that gulp-shell (recommended by other answers) is actually blacklisted by gulp, but thankfully you don't even need a plugin. Try this instead:

    // gulpfile.js
    
    const { watch } = require('gulp')
    var exec = require('child_process').exec
    
    function test (cb) {
      exec('python manage.py test', function (err, stdout, stderr) {
        console.log(stdout)
        console.log(stderr)
        cb(err)
      })
    }
    
    exports.default = function () {
      watch('./**/*.py', test)
    }
    

    In the past, I've tried many of the options suggested in other answers. This one was comparatively painless. It's helpful if you have some knowledge of JavaScript.

提交回复
热议问题