python - Pytest not able to register command line arguments
问题描述
This is my folder structure:
service
|
|--foolib
|
|--src
|
|--main
|
|--python3
|
|--foolib
|
|--conftest.py
and I run pytest from the root directory (service)
Here are the contents of conftest.py:
import pytest
def pytest_addoption(parser):
parser.addoption("--dc", action="store", dest="dc")
def pytest_configure(config):
DC = config.getoption("dc")
#do something with DC
When I run pytest from the root directory:
==================================================================================================================== test session starts =====================================================================================================================
platform darwin -- Python 3.8.2, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
rootdir: /Users/test/service
plugins: testrail-2.5.3
collected 0 items / 1 error
=========================================================================================================================== ERRORS ===========================================================================================================================
_______________________________________________________________________________________________________________ ERROR collecting test session ________________________________________________________________________________________________________________
python3.8/site-packages/_pytest/config/__init__.py:1463: in getoption
val = getattr(self.option, name)
E AttributeError: 'Namespace' object has no attribute 'dc'
....
E ValueError: no option named 'dc'
================================================================================================================== short test summary info ===================================================================================================================
ERROR - ValueError: no option named 'dc'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
====================================================================================================================== 1 error in 0.15s ======================================================================================================================
How can I resolve this? Am I missing something in the conftest?
解决方案
推荐阅读
- c++ - SystemParametersInfoA 和 SystemParametersInfo 有什么区别?
- regex - 如何在颤振中使用正则表达式?
- php - 使用hotmail发送邮件时无法检测结果?
- android - 如何通过在弹出窗口内单击来关闭弹出窗口?
- jquery - 如何将视图中的数组传递给 ajax 并在 Laravel 5 的控制器中访问?
- kubernetes - Kubernetes - pod 到 pod 通信协议
- java - 无法将图像文件选择器意图中的捆绑数据传递给 onActivityResult
- node.js - 调用 gRPC 服务器不会在 Node 中返回预期的数据
- css - CSS 粘性标题的间隙问题(仅限移动设备)
- postgresql - Postgres 角色和用户 - 表的权限被拒绝