Test if code is executed from within a py.test session

前端 未结 6 1398
被撕碎了的回忆
被撕碎了的回忆 2020-12-08 18:19

I\'d like to connect to a different database if my code is running under py.test. Is there a function to call or an environment variable that I can test that will tell me i

6条回答
  •  抹茶落季
    2020-12-08 19:11

    Working with pytest==4.3.1 the methods above failed, so I just went old school and checked with:

    if 'pytest' in sys.argv[0]:
      print('pytest was called!')
    

提交回复
热议问题