如何解决Jenkins上的python“测试”阶段错误?

我正在尝试在 Jenkins 上构建 CI/CD 流程。我在 Jenkins 上更新了我的文件,但在某个测试阶段,代码测试失败,但在我的本地机器上没有失败。

Jenkins 上的测试错误显示:

+ python cidr_convert_api/python/tests.py
..E..E
======================================================================
ERROR: test_invalid_mask_to_cidr (__main__.TestStringMethods)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "cidr_convert_api/python/tests.py",line 30,in test_invalid_mask_to_cidr
    self.assertEqual('Invalid',self.convert.mask_to_cidr('0.0.0.0'))
  File "/var/lib/jenkins/workspace/WL_Interview/cidr_convert_api/python/convert.py",line 17,in mask_to_cidr
    values = list(map(lambda x: 8 - math.log2(2**8 - int(x)),values))
  File "/var/lib/jenkins/workspace/WL_Interview/cidr_convert_api/python/convert.py",in <lambda>
    values = list(map(lambda x: 8 - math.log2(2**8 - int(x)),values))
AttributeError: 'module' object has no attribute 'log2'

======================================================================
ERROR: test_valid_mask_to_cidr (__main__.TestStringMethods)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "cidr_convert_api/python/tests.py",in test_valid_mask_to_cidr
    self.assertEqual('1',self.convert.mask_to_cidr('128.0.0.0'))
  File "/var/lib/jenkins/workspace/WL_Interview/cidr_convert_api/python/convert.py",values))
AttributeError: 'module' object has no attribute 'log2'

----------------------------------------------------------------------
Ran 6 tests in 0.000s

FAILED (errors=2)

在我的本地机器上通过的测试如下所示:

Image of passed test on machine

最后,构建的视图如下所示: jenkins dashboard

我有一个 dockerfile、API 文件和其他中间件,如果您需要其中任何一个以获得更多上下文,请提出请求。

我真的很感激谁能帮忙。谢谢!

iCMS 回答:如何解决Jenkins上的python“测试”阶段错误?

由于我的本地PC python和Jenkins Python不一样,我不得不通过docker的python测试命令,它运行起来很舒服。

我刚刚添加了 RUN python ./tests.py,它的作用就像魔法一样。

谢谢!

本文链接:https://www.f2er.com/481439.html

大家都在问