Hello New to python pytest-BDD I have a feature file that where everything after part of the when statement is to be parsed as a variable python side. But when doing so i get the following error
‘Step definition is not found: When “SQL to execute:”‘.Is there a setting for parsing text after a point for a when statement or should I change the feature file ?
Python code
import teradatasql, pytest ,logging, re
from pytest_bdd import given, when, then, scenarios, parsers
COL_DELIM = "|"
LOG = logging.getLogger(__name__)
host = ""
user = ""
password = ""
logmech = ""
actualResult = None
parametersused =""
scenarios("../feature.feature")
conn = None
@pytest.fixture(autouse=True)
def setUp(request):
global conn
conn = getConnection()
def tearDown():
global conn
close(conn)
request.addfinalizer(tearDown)
@given(parsers.parse("{parameters}"))
def ParseParmeters(parameters):
#used to called given
global parametersused
parametersused = str(parameters)
@when(parsers.parse("I execute the query:{queryTemplate}"))
@when(parsers.parse("SQL to execute:{queryTemplate}"))
def whenIExecuteTheQuery(queryTemplate):
global LOG, conn,actualResult,parametersused
actualResult = None
LOG.debug("QueryTemplate=" + queryTemplate + "/n Parameters: " + parametersused)
query = populateParameters(parametersused, queryTemplate)
LOG.info("Executing query:" + query)
stat = None
rs = None
try:
stat = conn.cursor()
rs = stat.execute(query)
LOG.info("Got result: n" + rs)
except Exception as error:
LOG.error("Error executing query: " + query, error)
raise Exception(error)
finally:
close(stat)
close(rs)
Feature file
Feature:Check if data of given attributes is NOT NULL
Scenario: Duplicate_check
Given <parameters>
When SQL to execute:
SELECT
'%TST_CD' AS Test
,(SELECT DATE FROM {$ENV}V_UTIL.PROCESSING_DATES WHERE PROC_DATE_TYP_CD = '%Proc_Typ_Cd') AS Business_Date
,'%Data_Entity' AS Data_Entity
,'%Data_Attribute' AS Data_Attribute
,'FAIL' AS Test_Sql_Status
FROM
(
SELECT CASE WHEN COUNT(1) = 0 THEN 'PASS' ELSE 'FAIL' END AS TST_RESULT
FROM ( SELECT ID
FROM ExampleTable
WHERE PROCESS_NAME='H35IDLR271LMT'
GROUP BY 1,2
HAVING COUNT(1) > 1)A
) tst_SQL
WHERE tst_SQL.tst_Result = 'Fail';
Then EXPECTED_RESULT=NO_ROWS_RETURNED
Examples:
|parameters|
|TST_CD=TST_CD_Example; Data_Entity=Data_EntityEX ; PROCESS_NAME=PROCESS_NAME_EXAMPLE ; Data_Attribute=Data_Attribute1,Data_Attribute2 Proc_Typ_Cd=Proc_Typ_Cd_name|