Skip to content

Commit e66152c

Browse files
authored
Update "problems with Non-DB test collection" section in TESTING.rst (apache#36300)
* add documentation on testing no-db with fixtures * remove pytest.param
1 parent 5c1d8f4 commit e66152c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

TESTING.rst

+30
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,36 @@ You can make the code conditional and mock out the Variable to avoid hitting the
703703
def test_rendered_task_detail_env_secret(patch_app, admin_client, request, env, expected):
704704
...
705705
706+
You can also use fixture to create object that needs database just like this.
707+
708+
709+
.. code-block:: python
710+
711+
from airflow.models import Connection
712+
713+
pytestmark = pytest.mark.db_test
714+
715+
716+
@pytest.fixture()
717+
def get_connection1():
718+
return Connection()
719+
720+
721+
@pytest.fixture()
722+
def get_connection2():
723+
return Connection(host="apache.org", extra={})
724+
725+
726+
@pytest.mark.parametrize(
727+
"conn",
728+
[
729+
"get_connection1",
730+
"get_connection2",
731+
],
732+
)
733+
def test_as_json_from_connection(self, conn: Connection):
734+
conn = request.getfixturevalue(conn)
735+
...
706736
707737
708738
Running Unit tests

0 commit comments

Comments
 (0)