我刚刚开始使用pytest和pytest xdist,在远程主机上执行测试。
远程主机(windows)正在使用上的socketserver.py模块https://pytest.org/latest/xdist.html
我的问题是,似乎每次执行测试时,socketserver都会在以前的pyexecnetcache目录中创建一个新的pyexecnetcache,并失败,返回以下错误消息:
=================================== ERRORS ====================================
_______________________ ERROR collecting test_sample.py _______________________
import file mismatch:
imported module 'test_sample' has this __file__ attribute:
C:pyexecnetcachetest_sample.py
which is not the same as the test file we want to collect:
C:pyexecnetcachepyexecnetcachetest_sample.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test
file modules
测试由执行
py.test -d --tx socket=myhost:8888 --rsyncdir test_sample.py test_sample.py
如何在每次运行后删除缓存?
我已经尝试将以下内容添加到socketserver.py中:
import sys
sys.dont_write_bytecode = True
@bjarneMichelsen
好吧,还有其他选择可以尝试。。。在windows中,你可以尝试在source上直接设置这个,比如。。
import sys
sys.dont_write_bytecode = True
现在,对于-B选项。。您可以尝试导出变量PYTHONDONTWRITEBYTECODE=1,而不是设置python标志
它在[python docs]上有描述(https://docs.python.org/2/using/cmdline.html#envvar-PYTHONDONTWRITEBETECODE)
尝试导出PYTHONFLAGS变量:
export PYTHONFLAGS=-B