1

我正在使用django-jenkins v0.110.0覆盖 v5.2.1,以及Django v3.1。如主题中所述,当我运行时:

python manage.py jenkins --enable-coverage

我收到此错误:

AttributeError:“覆盖”对象没有属性“数据”

下面是整个堆栈回溯:

Traceback (most recent call last):
  File "manage.py", line 16, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.8/site-packages/django_jenkins/management/commands/jenkins.py", line 47, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File "/usr/local/lib/python3.8/site-packages/django/core/management/commands/test.py", line 23, in run_from_argv
    super().run_from_argv(argv)
  File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.8/site-packages/django_jenkins/management/commands/jenkins.py", line 116, in handle
    coverage.save(tested_locations, options)
  File "/usr/local/lib/python3.8/site-packages/django_jenkins/tasks/with_coverage.py", line 29, in save
    self.coverage.stop()
  File "/usr/local/lib/python3.8/site-packages/django_jenkins/tasks/with_coverage.py", line 55, in get_morfs
    return [filename for filename in coverage.data.measured_files()
AttributeError: 'Coverage' object has no attribute 'data'

tests.py 中的测试方法运行正常,并在报告目录下生成了 junit.xml。但是肯定没有覆盖报告,因为这个错误。我在这里错过了什么吗?我应该指定一个覆盖配置文件(coverage.rc)让它工作吗?是不是和python3.8不兼容?其他问题?

任何想法都非常感谢。提前致谢!

4

2 回答 2

1

这已经很晚了,但是以防其他人在使用 django-jenkins 和覆盖范围时遇到这个问题。我设法通过使用coverage==4.3.4让它再次工作。我这样做是因为从 django-jenkins github 我看到他们正在使用这个版本的覆盖率。

于 2021-11-20T06:20:12.623 回答
1

You have a dependency problem. django-jenkins latest release was in september 2016. django v3 was released in september 2019. You would have to downgrade django to a release from that period in time.

I strongly advice you to not solve this problem but rather select a different solution other than django-jenkins.

Personally, I use tox so I can deploy my testing and tooling on any ci/cd tooling combined with calling coverage/pytest and any and all tooling (black, mypy, safety, flake8 etc) directly. Wrapper libraries such as django-jenkins are simply too unreliable or make features unaccessible due to wrapping. Take my tox.ini if you need an advanced start.

Good luck.

于 2020-09-21T21:38:49.207 回答