Python 一次运行所有项目测试,但也能够独立运行它们(同时必须提供输入数据路径)
我的测试有以下文件夹结构:Python 一次运行所有项目测试,但也能够独立运行它们(同时必须提供输入数据路径),python,python-3.x,unit-testing,testing,python-unittest,Python,Python 3.x,Unit Testing,Testing,Python Unittest,我的测试有以下文件夹结构: python-tests tests-folder-1 input-data <files_with_input_data_for_tests_from_this_folder> test_1.py test_2.py tests-folder-2 input-data
python-tests
tests-folder-1
input-data
<files_with_input_data_for_tests_from_this_folder>
test_1.py
test_2.py
tests-folder-2
input-data
<files_with_input_data_for_tests_from_this_folder>
test_something_else_1.py
test_something_else_2.py
run.py
如果可能的话,我希望避免修改系统路径。在test\u sth.py中,使用这个来获取测试数据
path = os.path.dirname(__file__)
TESTDATA = os.path.join(path, 'input-data/files_with_input_data_for_tests_from_this_folder.data')
昨天我在重读这个问题时发现了这一点,但是谢谢你的回答。也许是最简单的解决办法。
path = os.path.dirname(__file__)
TESTDATA = os.path.join(path, 'input-data/files_with_input_data_for_tests_from_this_folder.data')