'KeyError(key) Error in Pytest cx_Oracle connection error
Hey I tried to connect oracle db in pytest It shows following error raise KeyError(key) KeyError: 'db'
code
@pytest.fixture
def session():
config_file="dataflow.ini"
config_path = "%s/%s" % (os.path.dirname(os.path.abspath(sys.argv[0])),config_file)
config_ini = configparser.ConfigParser()
config_ini.read(config_path)
print("db" in config_ini)
# create oracle connection
dsn_tns = cx_Oracle.makedsn(config_ini['db']['host'], config_ini['db']['port'],
config_ini['db']['sid'])
dbs = cx_Oracle.Connection(config_ini['db']['user'], config_ini['db']['passwd'],dsn_tns)
db_session = dbs.cursor()
# db_session = connection.cursor()
yield db_session
connection.close()
dataflow.ini
[db]
sid=****
user=***
passwd=*****
host=****
port=****
[encryption]
key=********
Traceback error
self = <configparser.ConfigParser object at 0x7f01c9b93198>, key = 'db'
def __getitem__(self, key):
if key != self.default_section and not self.has_section(key):
raise KeyError(key)
E KeyError: 'db'
/usr/lib64/python3.6/configparser.py:959: KeyError -------------------------------------------------- Captured stdout setup -------------------------------------------------- False ================================================= short test summary info ================================================= ERROR scripts/pytest_test_vai.py::test_get - KeyError: 'db' ==================================================== 1 error in 1.13s =====================================================
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
