【发布时间】:2021-01-28 12:32:12
【问题描述】:
在我的项目中,我使用一个名为“conf.py”的文件来存储几个配置变量,例如保存文件的基本路径。
# conf.py:
'''
global variables and settings
'''
# Number of nodes in the graph
NODECOUNT = 1206
# save location
BASEPATH = 'data/'
包的其他部分通过从“conf.py”导入变量来加载它们。 使用 pytest 进行测试时,我需要这些变量的其他值才能被导入的包使用。这有可能吗?
编辑: 我当前的 pytest 文件如下所示:
import pytest
import my_packages
# set up a small graph to test on
s = structure(data, name) # structure uses conf.NODECOUNT
save(conf.BASEPATH + name, s)
# Tests
class TestOneClass:
def test_some_function():
res = some_function(name) # loads data from 'conf.BASEPATH/name'
assert res == expected_res
# more tests after
【问题讨论】: