即時通訊工作pytest權利知道。我的問題是我需要使用另一個test_file2.py中的test_file1.py中生成的同一個對象,這些對象位於兩個不同的目錄中,並分別從另一個目錄中調用。從不同的PyTest測試文件中使用相同的對象?
繼承人的代碼:
$ testhandler.py
# Starts the first testcases
returnValue = pytest.main(["-x", "--alluredir=%s" % test1_path, "--junitxml=%s" % test1_path+"\\JunitOut_test1.xml", test_file1])
# Starts the second testcases
pytest.main(["--alluredir=%s" % test2_path, "--junitxml=%s" % test2_path+"\\JunitOut_test2.xml", test_file2])
正如你所看到的第一個是至關重要的,因此,我-x啓動它打斷,如果有一個錯誤。並且 - 在開始新測試之前,_alluredir刪除目標目錄。這就是爲什麼我決定在我的testhandler.py兩次調用pytest(moreoften在未來也許)
這裏是test_files:
$ test1_directory/test_file1.py
@pytest.fixture(scope='session')
def object():
# Generate reusable object from another file
def test_use_object(object):
# use the object generated above
注意的對象實際上是與參數和功能的類。
$ test2_directory/test_file2.py
def test_use_object_from_file1():
# reuse the object
我試圖在testhandler.py文件中生成對象並將它導入到兩個測試文件中。問題在於該對象與testhandler.py或test_file1.py中的對象不一樣。
我的問題是現在是否有可能使用excatly那一個生成的對象。也許在全球conftest.py或類似的東西。
謝謝你的時間!