Skip to content

fixture teardown does not seems to execute #9995

@tr-gis

Description

@tr-gis

My tests directory structure is as follows:


tests
|---- conftest.py
|---- helper.py
|---- object1
      |----conftest.py
      |----test_object1.py
 

contents of conftest.py on the top level is as follows:

import pytest
from .helper import *


@pytest.fixture(scope='session')
def object_manager():
    def _dispatcher(object_name, data, method ): 
           
        response = send_request(object_name, data, method)   <--- creates object
        print('Before yield')
        yield response
        print('After yield')
        response = send_request(object_name, data, method)    <-- deletes object
            
    return _dispatcher

I use this fixture in test_object1.py within object1 directory. The contents of test_object1.py is as follows:

import pytest

def test_setup(object_manager):
    response = next(object_manager(object_name=POD, data=values_for_new_object()))
    assert response['success'] 

Then I run pytest with options to show setup for fixtures and capture set to no using the following command:
pytest --setup-show -s and got the following output:

================================================================================= test session starts ==================================================================================
platform linux -- Python 3.8.10, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /home/abs/Desktop/user/project/tests
plugins: anyio-3.3.4
collected 1 item                                                                                                                                                                       

object1/test_object1.py 
SETUP    S object_manager
        object1/test_object1.py::test_setup (fixtures used: object_manager)Before yield
.
TEARDOWN S object_manager

================================================================================== 1 passed in 0.10s ===================================================================================

From this I can see that my fixture entered it's SETUP phase, where it created the object like it is supposed to, it even prints the 'Before yield' statement I put in there for debugging. Next the asserts in my test_setup function pass, I get the green dot too.

However when the fixture enters TEARDOWN phase it does not seem to delete the object. There is nothing wrong with send_request() function , I checked. The statement "After yield" should be printed when the fixture enters TEARDOWN phase, I do not see it in the output. I feel like all the code below yield are not executed. Could you please tell me what went wrong here ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions