如果我使用命令“pytest -s -v”运行测试用例,我的测试用例将获取 pytest.ini 文件所在的根目录路径。
但我想在 python 测试会话开始之前以编程方式在“conftest.py”文件中或从“api”文件夹中的文件中找到根目录。请注意:我想在 pytest 测试会话开始之前获取根目录
我在互联网上进行了大量搜索,但没有得到满足我要求的答案。请帮忙
我的Python自动化项目结构如下。
api-automation
api
packagename
__init__.py
user.py
payloads
a.json
b.json
tests
test_1.py
test_2.py
conftest.py
setup.cfg
setup.py
pytest.ini
README.rst
Run Code Online (Sandbox Code Playgroud)
conftest.py的内容如下
import pytest
@pytest.fixture(scope='session', autouse=True)
def root_directory(request):
"""
:return:
"""
return str(request.config.rootdir)
Run Code Online (Sandbox Code Playgroud)
test_1.py的内容如下,
def test_first(root_directory):
print("root_directory", root_directory)
Run Code Online (Sandbox Code Playgroud) 我需要在 python 中模拟所有 AWS 服务(例如:EC2、S3、Redshift、Lambda、Dynamodb 等)。我正在使用 pytest 框架来编写测试用例,我发现了用于模拟 AWS 服务的“pytest-localstack”插件。但我也发现了更多的工具,如 moto、localstack。我也知道 boto3 可用于与 AWS 云进行交互。
我觉得“pytest-localstack”最适合我的要求,但请提供您的建议,我可以继续使用它还是需要使用其他工具。谢谢你的帮助。
这个问题可能看起来重复,但我已经尝试了很多但没有成功。我正在尝试使用https://slack.com/api/files.upload API上传 html 文件,但总是遇到以下错误。响应 {'ok': False, 'error': 'no_file_data'}
我浏览了文档[链接] https://api.slack.com/methods/files.upload并尝试了不同的选项,但我仍然得到相同的响应 {'ok': False, 'error': 'no_file_data' }
我还在堆栈溢出中看到了许多类似的问题,但没有一个解决了问题。[链接]使用 Slack API 上传时出现 no_file_data 错误 [链接]如何使用 file.upload 和 requests 将文件上传到 slack
下面是我的代码。
import requests
def post_reports_to_slack(html_report):
"""
"""
url = "https://slack.com/api/files.upload"
# my_file = {html_report, open(html_report, 'rb'), 'html'}
data = {
"token": bot_user_token,
"channels": channel_name,
"file": html_report,
"filetype": "html"
}
# data = "token=" + bot_user_token + \
# "&channels=" + channel_name +\
# "&file=" + html_report + "&filetype=" + …Run Code Online (Sandbox Code Playgroud)