如何使用Pytest结合Python读取ini配置文件?

2026-05-21 14:531阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计182个文字,预计阅读时间需要1分钟。

如何使用Pytest结合Python读取ini配置文件?

原句:伪原创以下开头内容,不要数落,不超过100个字,直接输出结果:福音不啰嗦,直接上代码+[host]+api_sit_url=https://api.binstd.com

废话不罗嗦,直接上代码

[host]
api_sit_url = api.binstd.com

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project :Pytest
@File :read_ini.py
@IDE :PyCharm
@Author :zhou
@Date :2022/8/7 9:47
"""
import configparser
import os
# 获取settings_ini文件里面的URL
path = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "config", "settings_ini")


def read_ini():
config = configparser.ConfigParser()
config.read(path, encoding="utf-8")
return config


print(read_ini()['host']['api_sit_url'])

代码不是关键,主要是自己的一个逻辑要有

如何使用Pytest结合Python读取ini配置文件?

本文共计182个文字,预计阅读时间需要1分钟。

如何使用Pytest结合Python读取ini配置文件?

原句:伪原创以下开头内容,不要数落,不超过100个字,直接输出结果:福音不啰嗦,直接上代码+[host]+api_sit_url=https://api.binstd.com

废话不罗嗦,直接上代码

[host]
api_sit_url = api.binstd.com

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project :Pytest
@File :read_ini.py
@IDE :PyCharm
@Author :zhou
@Date :2022/8/7 9:47
"""
import configparser
import os
# 获取settings_ini文件里面的URL
path = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "config", "settings_ini")


def read_ini():
config = configparser.ConfigParser()
config.read(path, encoding="utf-8")
return config


print(read_ini()['host']['api_sit_url'])

代码不是关键,主要是自己的一个逻辑要有

如何使用Pytest结合Python读取ini配置文件?