GispoCoding / pytest-qgis

A pytest plugin for testing QGIS python plugins
GNU General Public License v2.0
29 stars 8 forks source link

pytest_runtest_teardown fails while trying to clean MagicMocks with QgsVectorLayer spec #53

Closed Joonalai closed 6 months ago

Joonalai commented 9 months ago

Describe the bug A TypeError: isdeleted() argument 1 must be sip.simplewrapper, not MagicMock is raised when using MagicMock with QgsVectorLayer spec as a fixture with "layer" name.

https://github.com/GispoCoding/pytest-qgis/blob/af7f77aa962175263dcbcbbdce31afeeb6e842e8/src/pytest_qgis/utils.py#L210

To Reproduce Here is a sample test that gives the error (requires pytest-mock plugin, but stdlibs mock can be used as well):

@pytest.fixture()
def stub_layer(
    mocker,
) -> MagicMock:
    return mocker.MagicMock(
        spec=QgsVectorLayer,
        autospec=True,
    )

def test_stub_layer(stub_layer):
    assert isinstance(stub_layer, QgsVectorLayer)

Expected behavior Cleaning should ignore mocks.

Environment (please complete the following information):