1.Pytest之Fixture介绍
import pytest
@pytest.fixture
def first_fix():
return ['a']
def test_case01(first_fix):
first_fix.append("b")
print(first_fix)
if __name__ == '__main__':
pytest.main(['-s'])
def first_fix():
return ["a"]
def test_case(varA):
varA.append("b")
print(varA)
varA = first_fix()
test_case(varA)
2.Fixture调用Fixture
import pytest
@pytest.fixture
def first_fix():
return {
'username':'admin','password':'admin123'}
@pytest.fixture
def order(first_fix):
first_fix['aaa'] = '1111'
return first_fix
def test_string(order):
print(order)
if __name__ == '__main__':
pytest.main(['-s','test_append_03.py'])
def first_entry():
return "a"
def order(first_entry):
return [first_entry]
def test_string(order):
order.append("b"