简体   繁体   English

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

[英]How to solve a python "test" stage error on Jenkins?

I am trying to build a CI/CD flow on Jenkins.我正在尝试在 Jenkins 上构建 CI/CD 流程。 I have my file updated on Jenkins but at a certain test stage, the code test fails meanwhile it does not fail in my local machine.我在 Jenkins 上更新了我的文件,但在某个测试阶段,代码测试失败,同时它在我的本地机器上没有失败。

The test error on Jenkins is shown: 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", line 17, 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", line 17, 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", 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", line 17, in <lambda>
    values = list(map(lambda x: 8 - math.log2(2**8 - int(x)), values))
AttributeError: 'module' object has no attribute 'log2'

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

FAILED (errors=2)

The passed test on my local machine is shown thus:我的本地机器上通过的测试如下所示:

Image of passed test on machine在机器上通过测试的图像

Then finally, a view of the build is shown thus: jenkins dashboard .最后,构建视图如下所示: jenkins dashboard

I have a dockerfile, the API file and other middleware and if you need any of them for more context, please request.我有一个 dockerfile、API 文件和其他中间件,如果您需要其中任何一个以获得更多上下文,请索取。

I'd really appreciate who could help in. Thanks!我真的很感谢谁能提供帮助。谢谢!

Due to the dissimilarity between my local PC python and the Jenkins Python, I had to pass the python test command from docker and it ran comfortably. Due to the dissimilarity between my local PC python and the Jenkins Python, I had to pass the python test command from docker and it ran comfortably.

I just added RUN python./tests.py and it worked like magic.我刚刚添加了RUN python./tests.py它就像魔术一样工作。

thanks!谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM