How do I correctly setup and teardown for my pytest class with tests?

后端 未结 6 1018
名媛妹妹
名媛妹妹 2020-11-30 21:50

I am using selenium for end to end testing and I can\'t get how to use setup_class and teardown_class methods.

I need to set up browser in <

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-30 22:01

    import pytest
    class Test:
        @pytest.fixture()
        def setUp(self):
            print("setup")
            yield "resource"
            print("teardown")
    
        def test_that_depends_on_resource(self, setUp):
            print("testing {}".format(setUp))
    

    In order to run:

    pytest nam_of_the_module.py -v 
    

提交回复
热议问题