pytestフィクスチャをtest_ *関数でもフィクスチャでもない単純な関数から参照する(そして呼び出す)方法はありますか?簡単な(テストではない)関数からpytestフィクスチャを直接参照する方法はありますか?
1)私はこれを行うことができるようにしたい
def test_mytest(some_cool_pytest_fixture_name, the, rest of, my, args):
blah
blah
some_cool_pytest_fixture_name(args)
blah
2)
@pytest.fixture()
def my_new_fixture(some_cool_pytest_fixture_name, the, rest of, my, args):
blah
blah
some_cool_pytest_fixture_name(args)
blah
: 3)
def my_simple_function(the, rest of, my, args):
blah
blah
outright.reference.this.pytest.fixture.some_cool_pytest_fixture_name(args)
blah
注:
を器具を使用することができます知られている例
from pytest import record_xml_property as property_handler
** E ImportError: cannot import name record_xml_property**
^^^ record_xml_propertyを持っている。この中にシステム
私の欲求は、このような何かできるようにすることです:上記の成功できる場合
try:
from pytest import record_xml_property as property_handler
except:
@pytest.fixture()
def property_handler(mykey, myval):
print('{0}={1}'.format(mykey,myval)
を^^^、私はいつもproperty_handlerに依存することができます。
テストコードは、アプリケーションコードをインポートする必要があります。アプリケーションからテストコードをインポートする必要はありません。 Pytestテストランナーは、[アサーションの書き換え](https://docs.pytest.org/en/latest/assert.html#advanced-assertion-introspection)やサルのパッチ適用などの一連の魔法を実行します。 Pytestフィクスチャはpytestの外で動作するようには設計されていません。 –
いくつかの共有機能が必要な場合は、テストにインポートしてpytest.fixtureにラップしてください。 property_handler' としてpytest輸入record_xml_property ** EはImportErrorから –