Unpacking multiple arguments in pytest

拟墨画扇 提交于 2019-12-12 20:19:50

问题


I stumbled upon this question that has no answer. The OP asks to unpack several variables (using pytest fixtures) and make them have their local name available to the testing function. I thought I had a clean solution, involving automatic unpacking of a dictionary:

import pytest

@pytest.fixture  
def my_fix():
    return {"A" : 4, "B": 6 }


def test_something(my_fix):
    locals().update(my_fix)

    assert A == 4
    assert B == 6

This is inspired by this answer in Quora. When I run this test using pytest, it fails, because there seems to be no local variables called A or B!

Anyone willing to shed some light on why this happens? Also, an answer to the original question would be greatly appreciated.

来源:https://stackoverflow.com/questions/49808989/unpacking-multiple-arguments-in-pytest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!