You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2023/12/19 23:48:30 UTC
(airflow) branch main updated: Update "problems with Non-DB test collection" section in TESTING.rst (#36300)
This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new e66152c7ad Update "problems with Non-DB test collection" section in TESTING.rst (#36300)
e66152c7ad is described below
commit e66152c7adf919c3c4967476f51a723596626c20
Author: rom sharon <33...@users.noreply.github.com>
AuthorDate: Wed Dec 20 01:48:24 2023 +0200
Update "problems with Non-DB test collection" section in TESTING.rst (#36300)
* add documentation on testing no-db with fixtures
* remove pytest.param
---
TESTING.rst | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/TESTING.rst b/TESTING.rst
index 5c0e16bc26..df2f6044ac 100644
--- a/TESTING.rst
+++ b/TESTING.rst
@@ -703,6 +703,36 @@ You can make the code conditional and mock out the Variable to avoid hitting the
def test_rendered_task_detail_env_secret(patch_app, admin_client, request, env, expected):
...
+You can also use fixture to create object that needs database just like this.
+
+
+ .. code-block:: python
+
+ from airflow.models import Connection
+
+ pytestmark = pytest.mark.db_test
+
+
+ @pytest.fixture()
+ def get_connection1():
+ return Connection()
+
+
+ @pytest.fixture()
+ def get_connection2():
+ return Connection(host="apache.org", extra={})
+
+
+ @pytest.mark.parametrize(
+ "conn",
+ [
+ "get_connection1",
+ "get_connection2",
+ ],
+ )
+ def test_as_json_from_connection(self, conn: Connection):
+ conn = request.getfixturevalue(conn)
+ ...
Running Unit tests