Skip to main content
 首页 » 编程设计

python之django之在启动服务器时运行测试

2025年05月04日29itcoder

当使用 python manage.py runserver 启动服务器时,如何配置我的 Django 服务器以从 tests.py 运行测试?现在,我必须通过 python manage.py test articles 运行测试。 (注意:我使用的是 Django 1.8)

请您参考如下方法:

@limelights 的回答:

Create a bash alias or run them in sequence?

我已经将该答案改编为这行代码(用于 bash):

alias runserver="sudo python ~/testsite/manage.py test articles; sudo python ~/testsite/manage.py runserver 192.168.1.245:90(作为一行)

使用runserver 运行测试套件并打开服务器。一个额外的好处是我可以从任何位置运行它而无需进入 ~/testsite 目录。