在CircleCI上并行运行时,Django Unittest失败

时间:2017-07-21 06:01:35

标签: mysql django unit-testing circleci django-unittest

我正在使用1个容器设置在CircleCI上运行Django Unit测试。当我不添加Django的--parallel参数时,测试运行正常。但是,当我将--parallel=2添加到测试运行时,它会因下面的这个神秘错误而失败。

我已经尝试了两个版本:有和没有--keepdb - 两者都失败了完全相同的错误。 _clode_test_db的代码似乎表明传递--keepdb=True应该快速失败并返回。请参阅django/db/backends/mysql/creation.py第29行[https://github.com/django/django/pull/4761/files]

非常感谢有关此处发生的事情的任何想法

Using existing clone for alias 'default' ('test_django_learned')...
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/circleci/sliderule/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/home/circleci/sliderule/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/circleci/sliderule/venv/lib/python2.7/site-packages/django/core/management/commands/test.py", line 30, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File "/home/circleci/sliderule/venv/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/circleci/sliderule/venv/lib/python2.7/site-packages/django/core/management/commands/test.py", line 74, in execute
    super(Command, self).execute(*args, **options)
  File "/home/circleci/sliderule/venv/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/home/circleci/sliderule/venv/lib/python2.7/site-packages/django/core/management/commands/test.py", line 90, in handle
    failures = test_runner.run_tests(test_labels)
  File "/home/circleci/sliderule/venv/lib/python2.7/site-packages/django/test/runner.py", line 532, in run_tests
    old_config = self.setup_databases()
  File "/home/circleci/sliderule/venv/lib/python2.7/site-packages/django/test/runner.py", line 482, in setup_databases
    self.parallel, **kwargs
  File "/home/circleci/sliderule/venv/lib/python2.7/site-packages/django/test/runner.py", line 733, in setup_databases
    keepdb=keepdb,
  File "/home/circleci/sliderule/venv/lib/python2.7/site-packages/django/db/backends/base/creation.py", line 219, in clone_test_db
    self._clone_test_db(number, verbosity, keepdb)
  File "/home/circleci/sliderule/venv/lib/python2.7/site-packages/django/db/backends/mysql/creation.py", line 48, in _clone_test_db
    dump_proc = subprocess.Popen(dump_cmd, stdout=subprocess.PIPE)
  File "/usr/local/lib/python2.7/subprocess.py", line 390, in __init__
    errread, errwrite)
  File "/usr/local/lib/python2.7/subprocess.py", line 1024, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
Exited with code 1

1 个答案:

答案 0 :(得分:0)

我可以通过添加

来重现它并在我的ubuntu容器中调试问题
sys.stderr.write("dump_cmd: %r" % dump_cmd)

site-packages/django/db/backends/mysql/creation.py,它给了我

dump_cmd: ['mysqldump', '--user=root', '--password=pass', '--host=db', '--port=3306', 'test']

所以我的容器也可能丢失了mysqldump,我用简单的sudo apt-get install mysql-client修复了这个容器。