<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Dinesh</title>
    <description>The latest articles on DEV Community by Dinesh (@dinesh1105).</description>
    <link>https://dev.to/dinesh1105</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1271014%2Fcafb50c1-b49c-4d37-a7bb-3724850338a1.png</url>
      <title>DEV Community: Dinesh</title>
      <link>https://dev.to/dinesh1105</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dinesh1105"/>
    <language>en</language>
    <item>
      <title>Pytest How to pass .yaml file as argument in pytest command line</title>
      <dc:creator>Dinesh</dc:creator>
      <pubDate>Thu, 01 Feb 2024 10:24:08 +0000</pubDate>
      <link>https://dev.to/dinesh1105/pytest-how-to-pass-yaml-file-as-argument-in-pytest-command-line-eh4</link>
      <guid>https://dev.to/dinesh1105/pytest-how-to-pass-yaml-file-as-argument-in-pytest-command-line-eh4</guid>
      <description>&lt;p&gt;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 .&lt;/p&gt;

&lt;p&gt;test_code.yaml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;**.yaml file content :**

test_execute_impala_query:
- change_dir_path: /home/a/
  sql_result: ksh -x /home/impala_query.sh /sandbox/home/impala_export_query.sql  /sandbox/home/actual_result.csv output_delimiter=,

test_file_compare:
 - file_compare_check: python3 /sandbox/pytest_execution/test_compare_file.py  --file1 /sandbox/venv/smoke_test/actual_result_prsn.csv --file2 /sandbox/smoke_test/expected_result.csv 

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Actual Pytest script&lt;/p&gt;

&lt;p&gt;test_code_check.py&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;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
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the above code perfectly works fine but that .yaml filename I need to pass it through command line&lt;/p&gt;

&lt;p&gt;I have to execute the below way to get the output separately.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;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 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>pytest</category>
      <category>parameter</category>
      <category>argument</category>
      <category>yaml</category>
    </item>
  </channel>
</rss>
