Best Python code snippet using gabbi_python
test_pytest.py
Source:test_pytest.py
1# pytestæµè¯æ¡æ¶2import pytest3def func(x):4 return x + 15# åæ°å6@pytest.mark.parametrize('a,b', [7 (1, 2),8 (10, 20),9 ('a', 'a1'),10 (3, 4),11 (5, 6)12])13def test_answer(a, b):14 assert func(a) == b15def test_answer1():16 assert func(4) == 517# è£
饰å¨18@pytest.fixture()19def login():20 print('ç»å½æä½')21 username = 'chan'22 return username23class TestDemo:24 def testa(self):25 print('a')26 # test_aéè¦æåç»å½ï¼å°±ä¼ å
¥loginï¼å¨æ§è¡æµè¯ç¨ä¾åä¼å
æ§è¡loginæ¹æ³27 def test_a(self, login):28 print(f' username = {login}')29 def test_b(self):30 print('b')31 def test_c(self, login):32 print(f'c username = {login}')33if __name__ == '__main__':34 # pytest.main(['test_pytest.py'])35 # ç¸å½äºå½ä»¤å·æ§è¡ python test_pytest.py36 # pytest.main(['test_pytest.py::test_answer1','-v'])37 # pytest.main(['test_pytest.py::TestDemo','-v'])38 pytest.main(['test_pytest.py::TestDemo::test_b', '-v'])39 # å¨terminalä¸æ§è¡python test_pytest.pyæ¥çï¼...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!