我正在使用AWS CodeBuild对我的python代码执行单元测试。当我在CodeBuild中执行项目时,它成功完成但单元测试未正确执行。它给出了错误E NameError:未定义name add_numbers'
add_numbers是我的code.py文件中的一个模块,只添加了2个数字。
注意:此单元案例在本地成功运行。
这是我的code.py:
"""Test code to test the pylint & pytest"""
def add_numbers( number_1, number_2):
"""This module add 2 numbers that are given as input"""
return number_1+number_2
这是我的单元测试
"""This is unit test file"""
import code
def test_adding_module():
"""This module tests add_number module"""
result = code.add_numbers(12, 8)
assert result == 20
任何帮助表示赞赏。
我解决了这个问题。实际上pytest无法获得Python的路径。在Buildspec.yml中编写以下命令解决了这个问题。
`export PYTHONPATH=.`
这适用于Linux,如果你在Windows上使用
set PYTHONPATH=.