Pytest How to pass .yaml file as argument to pytest command line #11905
Unanswered
dinesh-11-05
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have multiple .yaml files each containing shell or python commands and I want to execute them separately based on the need through command line arguments in pytest execution .
test_code.yaml
`.yaml file content :
test_execute_impala_query:
sql_result: ksh -x /home/impala_query.sh /sandbox/home/impala_export_query.sql /sandbox/home/actual_result.csv output_delimiter=,
test_file_compare:
Actual Pytest script
test_code_check.py
`import pytest
import os
import parametrize_from_file
import pandas as pd
import subprocess
import sys
@parametrize_from_file
def test_execute_impala_query(change_dir_path,sql_result):
os.chdir(change_dir_path)
result = subprocess.run([sql_result],shell=True,check=True,stdout=subprocess.PIPE, universal_newlines=True)
assert result.returncode == 0
@parametrize_from_file
def test_file_compare(file_compare_check):
result = subprocess.run([file_compare_check],shell=True,check=True,stdout=subprocess.PIPE, universal_newlines=True)
assert result.returncode == 0`
Here, the above code perfectly works fine but that .yaml filename I need to pass it through command line
I have to execute the below way to get the output separately. The below way I execute the pytest scripts and get the test comes for different set of .yaml file as argument to pass and generate the output . Can you please suggestions/inputs that would be very helpful
`pytest test_code_check.py --test_file test_code.yaml
pytest test_code_check.py --test_file test_code_2.yaml
pytest test_code_check.py --test_file test_code_3.yaml
pytest test_code_check.py --test_file test_code_4.yaml`
Beta Was this translation helpful? Give feedback.
All reactions