2015-09-14 22 views
3

我期待創建一個pytest結構,我可以完全從測試中分離燈具。這種分離的原因是我想將fixtures目錄作爲外部項目包含在Subversion中並在多個項目之間共享。Pytest在一個單獨的目錄中的燈具

樹所需的結構

project 
| conftest.py 
| 
+---fixtures 
|  __init__.py 
|  conftest.py 
|  fixture_cifs.py 
|  fixture_ftp.py 
|  fixture_service.py 
| 
\---tests 
    | test_sometest1.py 
    | test_sometest2.py 
    | 
    \---configurations 
      sometest1.conf 
      sometest2.conf 

的我想要實現,以避免單一的巨大conftest.py在一個單獨的文件每個燈具的功能。 conftest.py只包含包裝器以返回每個夾具的實例,其註釋用@pytest.fixture。當conftest.pyfixture_*.pytest_*.py文件都在同一個目錄中時,使用夾具和測試是沒有問題的。

但是,當夾具在一個子目錄中分開時,我從pytest fixture 'cifs' not found,available fixtures: ...得到一個錯誤。我還沒有找到任何文件解釋如何將test_*.pyconftest.py附近的燈具放置在test_*.py附近,但沒有說明這不應該起作用。

如何在使用pytest時將燈具放在自己的子目錄中?

回答

1

閱讀here如何組織你的測試。

您的燈具目錄似乎不包(項目沒有__init__.py所以canno導入爲project.fixtures無論是作爲fixtures至於是不是在路徑。 您可以添加在路徑所需迪爾斯在tests/conftest.pysys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, "fixtures"))sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir)根據如何你想怎麼導入模塊。

0

你嘗試importproject/conftest.py荷蘭國際集團的燈具?這是你的意思「包裝返回的實例」

相關問題