conftest.py 内にオブジェクトを作成し、いくつかのフィクスチャで使用しています。また、テスト モジュール内でこのオブジェクトを使用する必要があります。現在、テスト モジュール内に conftest.py をインポートして、その「ヘルパー」オブジェクトを利用しています。これが推奨される方法ではないことは確かです。あなたの提案を楽しみにしています。
ありがとうございました :)
以下は私の質問のダミーコード版です:
conftest.py
import pytest
class Helper():
def __init__(self, img_path:str):
self.img_path = img_path
def grayscale(self):
pass
def foo(self):
pass
helper = Helper("sample.png")
@pytest.fixture()
def sample():
return helper.grayscale()
test_module.py
import conftest
helper = conftest.helper
def test_method1(sample):
helper.foo()
...