Python 2.7 指定--basetemp,同时保持每会话文件夹行为
使用pytest,在指定基本文件夹时是否有方法保持自动文件夹行为 我想将pytest文件夹从%TEMP%移动到特定的根目录,但在使用--basetemp参数时,pytest不会像以前那样为每个会话创建一个文件夹 不带--basetemp:Python 2.7 指定--basetemp,同时保持每会话文件夹行为,python-2.7,testing,pytest,Python 2.7,Testing,Pytest,使用pytest,在指定基本文件夹时是否有方法保持自动文件夹行为 我想将pytest文件夹从%TEMP%移动到特定的根目录,但在使用--basetemp参数时,pytest不会像以前那样为每个会话创建一个文件夹 不带--basetemp: %TEMP%\pytest-90 \test1() \test2() \test3() %TEMP%\pytest-91 \test1() \test
%TEMP%\pytest-90
\test1()
\test2()
\test3()
%TEMP%\pytest-91
\test1()
\test2()
\test3()
%TEMP%\pytest-92
\test1()
\test2()
\test3()
使用--basetemp=D:\Tests
D:\Tests
\test1()
\test2()
\test3()
这就是我想要实现的目标:
D:\Tests\pytest-90
\test1()
\test2()
\test3()
D:\Tests\pytest-91
\test1()
\test2()
\test3()
D:\Tests\pytest-92
\test1()
\test2()
\test3()
可行的变通办法:
- 从python启动py.test时,我可以自己创建文件夹 文件并将其设置为basetemp
- 实现我自己的夹具 提取tmpdir,然后从那里计算它
- 更改我的临时路径环境变量
但我在找一条内置的路?我们可以保持自动文件夹行为,同时指定新的basetemp吗?查看管理basetemp目录的代码,这在当前看来是不可能的:
def getbasetemp(self):
""" return base temporary directory. """
try:
return self._basetemp
except AttributeError:
basetemp = self.config.option.basetemp
if basetemp:
basetemp = py.path.local(basetemp)
if basetemp.check():
basetemp.remove()
basetemp.mkdir()
else:
basetemp = py.path.local.make_numbered_dir(prefix='pytest-')
self._basetemp = t = basetemp.realpath()
self.trace("new basetemp", t)
return t
我建议在会议上提出一个问题,看看其他人有什么要说的 查看管理basetemp目录的代码,这在当前看来是不可能的:
def getbasetemp(self):
""" return base temporary directory. """
try:
return self._basetemp
except AttributeError:
basetemp = self.config.option.basetemp
if basetemp:
basetemp = py.path.local(basetemp)
if basetemp.check():
basetemp.remove()
basetemp.mkdir()
else:
basetemp = py.path.local.make_numbered_dir(prefix='pytest-')
self._basetemp = t = basetemp.realpath()
self.trace("new basetemp", t)
return t
我建议在会议上提出一个问题,看看其他人有什么要说的 I set TEMP=logs和pytest在新文件夹下保留旋转编号的dir模型。这是py.path.local API的产品。另一方面,basetemp并非用于您请求的目的,它主要是一个用于固定日志目录的好工具,可能最适合在CICD中使用。I set TEMP=logs and pytest在新文件夹下保留旋转编号目录模型。这是py.path.local API的产品。另一方面,basetemp并非用于您请求的目的,它主要是一个用于固定日志目录的好工具,可能最适合在CICD中使用。更新:接受的答案是从2014年开始的,此后函数getbasetemp()发生了更改: 根据该代码,可以设置环境变量PYTEST_DEBUG_TEMPROOT。然后,文件夹的名称如下: PYTEST\u DEBUG\u TEMPROOT/PYTEST of USER/PYTEST NUMBER/popen gwX/
“popen gwX”等目录仅在使用pytest xdist更新时存在:接受的答案是2014年的,此后函数getbasetemp()发生了更改: 根据该代码,可以设置环境变量PYTEST_DEBUG_TEMPROOT。然后,文件夹的名称如下: PYTEST\u DEBUG\u TEMPROOT/PYTEST of USER/PYTEST NUMBER/popen gwX/ “popen gwX”等目录仅在使用pytest xdist时存在谢谢:)谢谢:)