@@ -248,3 +248,77 @@ def test_dbt_test_uses_correct_argument_according_to_version():
248248 assert getattr (op , "models" , None ) is None
249249 assert op .selector == "a-selector"
250250 assert getattr (op , "selector_name" , None ) is None
251+
252+
253+ GENERIC_TESTS_WITH_ARGUMENTS = """
254+ version: 2
255+
256+ models:
257+ - name: model_2
258+ columns:
259+ - name: field1
260+ tests:
261+ - not_null
262+ - accepted_values:
263+ arguments:
264+ values: ['123', '456']
265+ """
266+
267+
268+ @pytest .fixture (scope = "function" )
269+ def generic_tests_files_with_arguments (model_files , dbt_project_dir ):
270+ """Create a dbt generic test YAML file."""
271+ d = dbt_project_dir / "models" / "new"
272+ d .mkdir (exist_ok = True , parents = True )
273+
274+ schema = d / "schema.yml"
275+ schema .write_text (GENERIC_TESTS_WITH_ARGUMENTS )
276+
277+ return [schema ]
278+
279+
280+ @pytest .fixture (scope = "function" )
281+ def dbt_project_file_with_arguments_flag (dbt_project_dir , logs_dir , request ):
282+ """Create a test dbt_project.yml file with flag to require arguments."""
283+ p = dbt_project_dir / "dbt_project.yml"
284+ contents = """
285+ name: test
286+ profile: default
287+ config-version: 2
288+ version: 1.0.0
289+ flags:
290+ require_generic_test_arguments_property: true
291+ """
292+ p .write_text (contents )
293+
294+ return p
295+
296+
297+ def test_dbt_test_generic_tests_with_arguments (
298+ profiles_file ,
299+ dbt_project_file_with_arguments_flag ,
300+ generic_tests_files_with_arguments ,
301+ hook ,
302+ ):
303+ """Test a dbt test operator for a generic test with arguments.
304+
305+ Since the require_generic_test_arguments_property flag is enabled, this should pass.
306+ """
307+ hook .run_dbt_task (
308+ "run" ,
309+ project_dir = dbt_project_file_with_arguments_flag .parent ,
310+ profiles_dir = profiles_file .parent ,
311+ )
312+
313+ op = DbtTestOperator (
314+ task_id = "dbt_task" ,
315+ project_dir = dbt_project_file_with_arguments_flag .parent ,
316+ profiles_dir = profiles_file .parent ,
317+ generic = True ,
318+ )
319+ results = op .execute ({})
320+
321+ assert results ["args" ]["generic" ] is True
322+ assert len (results ["results" ]) == 2
323+ for test_result in results ["results" ]:
324+ assert test_result ["status" ] == TestStatus .Pass
0 commit comments