我试图在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", 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)本地计算机上通过的测试如下所示:
最后,展示了构建的一个视图:詹金斯仪表板。
我有一个dockerfile,API文件和其他中间件,如果您需要更多的上下文,请请求。
我真的很感激谁能帮忙。谢谢!
发布于 2021-05-03 11:29:22
由于本地PC Python和Jenkins python之间的不同,我不得不从docker中通过python测试命令,它就可以轻松地运行了。
我刚加了RUN python ./tests.py,效果就像魔法一样。
谢谢!
https://stackoverflow.com/questions/67367069
复制相似问题