Running Django test with setup.py test and toxicity

I built a Django application and made a package with setuptools . Now I would like to do the following:

  • I would like to run all tests using python setup.py test . But when I issue this command, I get:

     /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'install_requires' warnings.warn(msg) usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] or: setup.py --help [cmd1 cmd2 ...] or: setup.py --help-commands or: setup.py cmd --help error: invalid command 'test' 
  • I would like to use Tox to run my tests, but I have no idea what to write in the command attribute to run the tests in Django.

+6
source share
1 answer

in setup.py :

 test_suite = "test_project.runtests.runtests", 

And then in your project:

 #This file mainly exists to allow python setup.py test to work. import os, sys os.environ['DJANGO_SETTINGS_MODULE'] = 'test_project.settings' test_dir = os.path.dirname(__file__) sys.path.insert(0, test_dir) from django.test.utils import get_runner from django.conf import settings def runtests(): test_runner = get_runner(settings) failures = test_runner([], verbosity=1, interactive=True) sys.exit(failures) if __name__ == '__main__': runtests() 

See this tutorial by Eric Holscher.

+3
source

Source: https://habr.com/ru/post/956860/


All Articles