Click here to Skip to main content
15,888,340 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Consider we have within same root folder, we have conftest.py , setup.py ,teardown.py and testsomething.py

Python
#conftest.py
        ----------------------
    import pytest
    import setup // from setup import Test_Setup
    import teardown // from teardown import Test_Teardown

    @pytest.fixture(scope='module', autouse=True)
    def t(request):
        t = getT()
        request.addfinalizer(t.cleanup)
        return t

    @pytest.fixture(scope='module', autouse=True)
    def setup(t):
        // Here I want to execute class "Test_Setup" as pytest class

    @pytest.fixture(scope='module', autouse=True)
    def teardown(t):
        yield
        // Here I want to execute  class "Test_TearDown"as pytest class

     #setup.py
    ----------------------
    class Test_Setup:

        def test_creation(self, t):
         //test codes

        def test_setp1(self, t):
         //test codes

        def test_step2(self, t):
         //test codes

     #teardown.py
    ----------------------
    class Test_Teardown:

        def test_Reset(self,t):
           // some cleanup code

 #testsomething.py
    ----------------------
    class Test_Something:

        def test_1(self,t):
           // some cleanup code
         def test_2(self,t):
           // some cleanup code


we know before running test class and its function in testsomething.py pytest will run fixture setup and finally teardown defined in conftest.py

Problem is within these setup and teardown fixtures I want to run those pytest test classes defined in setup.py and teardown.py respectively.

Please Note : Those Test class execution should be executed as pytest Test class not like general class instantiation and call member function scenario and also we cannot touch testsometing.py definition, which means it should not related/imported with setup.py or teardown.py.

If you can provide a solution for python 2.7 that would be really helpful.
Thank you for the considering.

What I have tried:

I tried instantiation of Test_Setup and Test_Teardown, since this not my intetion, I wanted to run this Test classes as pytest class.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900