如何让 pytest 不要屏蔽被测试程序的标准输出?
def test_make_keyword_task( mock_category_mapping_track_source_ids,
mock_download_rule,
mock_get_uuid
):
# Mocking RawRecord
task = RawRecord(
company_id=1,
meta_type="image",
keyword="iphone",
file_path="/image/iphone.jpg",
meta_uuid="iphonx",
is_tracking="started"
)
# Mocking Rules
rules = {1: Rules(category={"some_category": {"nums": 1, "priority": 2}})}
# Calling the function to test
keyword_task_list = make_keyword_task(
task,
"some_url_root",
rules,
push_uuid=None,
category_mapping_track_source_ids=mock_category_mapping_track_source_ids
)
from loguru import logger
logger.debug(keyword_task_list)
print(keyword_task_list)
不管是最后的 logger.debug 还是 print 都不会显示了,很讨厌!
python -m pytest common
─➤ python -m pytest common/Users/ponponon/.local/share/virtualenvs/keyword_push-XlDIVWXu/lib/python3.10/site-packages/nameko/testing/pytest.py:101: UserWarning: For versions after 2.13.0, it is recommended to use the `nameko test` cli command. Nameko's pytest plugin no longer applies the eventlet monkeypatch as a pytest hook. This was removed to prevent polluting the environment in case a monkeypatch was not desired.
If you need to invoke pytest directly instead of using `nameko test`, you can install the pytest-eventlet plugin, which just performs the automatic monkeypatching that was removed from Nameko. Alternatively you can apply the monkeypatch manually in your conftest.py file.
This warning can be suppressed with the --suppress-nameko-eventlet-notification pytest option.
warnings.warn(
====================================== test session starts =======================================
platform darwin -- Python 3.10.10, pytest-7.4.3, pluggy-1.3.0
rootdir: /Users/ponponon/Desktop/code/work/xxxx-it/keyword_push
plugins: nameko-2.14.1, anyio-3.7.1
collected 1 item
common/test_common.py . [100%]
======================================== warnings summary ========================================
../../../../../.local/share/virtualenvs/keyword_push-XlDIVWXu/lib/python3.10/site-packages/kombu/utils/compat.py:82
/Users/ponponon/.local/share/virtualenvs/keyword_push-XlDIVWXu/lib/python3.10/site-packages/kombu/utils/compat.py:82: DeprecationWarning: SelectableGroups dict interface is deprecated. Use select.
for ep in importlib_metadata.entry_points().get(namespace, [])
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================== 1 passed, 1 warning in 0.16s ==================================
(keyword_push) ╭─ponponon@MBP13ARM ~/Desktop/code/work/xxxx-it/keyword_push ‹feature/v3*›
╰─➤
回答:
pytest 命令加一个 -s
就行
把 python -m pytest common
改成 python -m pytest -s common
以上是 如何让 pytest 不要屏蔽被测试程序的标准输出? 的全部内容, 来源链接: utcz.com/p/939059.html