pytest方法打开文件提示文件不存在,非pytest方法中正常

image

============================= test session starts ==============================
platform darwin – Python 3.7.4, pytest-5.3.5, py-1.8.1, pluggy-0.13.1
rootdir: /Users/miao/Desktop/github/cong/testcase
plugins: ordering-0.6
collected 1 item

…/…/…/…/Users/miao/Desktop/github/cong/testcase/test_yalm.py F
def test_json():

  f=open("calc.json")

E FileNotFoundError: [Errno 2] No such file or directory: ‘calc.json’

找到原因了,pytest运行路径不是当前路径,打开文件的时候写绝对路径就ok了,第一个帖子 :hugs:

写绝对路径在你本地是不会有问题了,但是你埋了个坑

还没踩到,愿闻其详

你换台电脑,或者把工程文件换个盘,甚至换个文件夹,都可以,100%报错