pytest_plugin全局变量如何工作?

时间:2019-03-27 12:55:00

标签: python pytest

我试图在一个名为redis.py(abc \ plgfix \ redis.py)的文件中定义束夹具,并通过pytest_plugin在我的测试用例(abc \ common \ test_file.py)中使用它们。这样做时,我注意到测试用例无法看到我定义的固定装置。

我的文件夹结构如下

abc
  |
  common
     |
      config.py    ( I have defined pytest_plugin=["plgfix.redis"]
      test_file.py
  plgfix
     |
      redis.py ( I have defined bunch of fixtures here)
      __init__.py

从上图

-> plgfix (folder) has my desired  file(redis.py) and __init__.py file to 
   make folder  as package.

-> In  abc\common\config.py. I have defined pytest_plugin global variable

     pytest_plugins = ["plgfix.redis"] #assuming all fixtures in 
                                 #redis.py file , available for test cases



->  Now I have created abc\common\test_file.py where I'm  using one of the 
    defined fixture in redis.py (abc\plgfix\redis.py) as follows.

     def test_fixtu(fix1):
          print ("Hi")
          pass


 I was getting error as  fix1 is not found

注意:我可以导入配置文件,并以' package ',' spec ','pytest_plugins'看到内容。......(确认这不是路径问题)

0 个答案:

没有答案