简体   繁体   English

configparser.NoSectionError: 没有部分: 'database'

[英]configparser.NoSectionError: No section: 'database'

Getting "configparser.NoSectionError: No section: 'database'" error while running from unnitest file.从 unnitest 文件运行时出现“configparser.NoSectionError: No section: 'database'”错误。

.py file .py 文件

import psycopg2 as pg2
from configparser import ConfigParser

parser = ConfigParser()
configFilePath = r'dev.ini'
parser.read(configFilePath)
print('1')

conn = pg2.connect(user=parser.get('database', 'user'),
                   password=parser.get('database', 'password'),
                   host=parser.get('database', 'host'),
                   port=parser.get('database', 'port'),
                   database=parser.get('database', 'database'))
print(conn.get_dsn_parameters(), "\n")
print('2')


def get_data_from_query(query):
    """return query output"""
    cur = conn.cursor()
    cur.execute(query)
    data_from_query = cur.fetchall()
    return data_from_query




def economical_bowlers(year,data_table_1="matches",data_table_2="deliveries"):
    query = """select c.bowler , sum(c.sum*6/c.count) 
        from (select a.bowler ,sum(a.total_runs - a.bye_runs - a.legbye_runs ),count(a.ball)
         from {2} a inner join {1} b 
         on a.match_id=b.id 
         where b.season='{0}' 
        group by a.bowler) 
        c group by c.bowler;""".format(year,data_table_1,data_table_2)
    data = get_data_from_query(query)
    return dict(data)

.py unittest file .py 单元测试文件

import unittest
import os
import sys

sys.path.insert(2, os.path.join(os.getcwd(), '..'))
import economical_bowlers
from Extractor import extractor
import ipl_project_sql


class Economical_bowlers(unittest.TestCase):

    def test_economical_bowlers(self):
        expected_matches_data_of_all_teams = {'AD Russell': 10, 'P Kumar': 6}
        calculated_matches_data_of_all_teams = ipl_project_sql.economical_bowlers('2015', data_table_1='matches',
                                                                                  data_table_2='deliveries')
        self.assertEqual(expected_matches_data_of_all_teams,
                         calculated_matches_data_of_all_teams)


if __name__ == '__main__':
    unittest.main()

Both files work perfectly when are independent.The second file just test the first files output.I just want to remove error.两个文件在独立时都可以完美运行。第二个文件只是测试第一个文件的输出。我只想删除错误。

我有一个用于加密的配置文件,它需要像测试文件夹一样位于安全文件夹中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python ConfigParser.NoSectionError:没有部分: - Python ConfigParser.NoSectionError: No section: configparser.NoSectionError:No section:'XXX' - configparser.NoSectionError:No section:'XXX' Python:ConfigParser.NoSectionError:没有部分:'TestInformation' - Python: ConfigParser.NoSectionError: No section: 'TestInformation' Python 2.4.3:ConfigParser.NoSectionError:没有部分:'formatters' - Python 2.4.3: ConfigParser.NoSectionError: No section: 'formatters' Python错误:ConfigParser.NoSectionError:无节: - Python error : ConfigParser.NoSectionError: No section: Flask-Migrate错误:“ ConfigParser.NoSectionError:无部分:'alembic” - Flask-Migrate Error: 'ConfigParser.NoSectionError: No section: 'alembic'' 轨道发射问题:“ ConfigParser.NoSectionError: No section: 'formatters' ” - Orbited launch problems: “ ConfigParser.NoSectionError: No section: 'formatters' ” Python:ConfigParser.NoSectionError:没有部分:“电子邮件” - Python: ConfigParser.NoSectionError: No section:'E-mail' ConfigParser.NoSectionError:无节:Exe中的“位置”。 蟒蛇 - ConfigParser.NoSectionError: No section: 'locations' in Exe. Python configparser.NoSectionError:没有部分:'BotValues' discord.py - configparser.NoSectionError: No section: 'BotValues' discord.py
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM