Coverage for test/tests/unit/test_item.py: 52.50%
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2 tests call.py
3"""
4# mypy: ignore-errors
5# pylint: disable=redefined-outer-name
6from unittest.mock import (
7 Mock,
8 patch,
9)
11import pytest
13from pytest_vulture import VultureError
14from pytest_vulture.item import VultureItem
17@pytest.fixture
18def mocker(monkeypatch):
19 """
20 Create a tmp dir
21 """
22 monkeypatch.setattr(
23 pytest.Item,
24 "__init__",
25 lambda *_, **_1: 1
26 )
27 monkeypatch.setattr(
28 pytest.File,
29 "__init__",
30 lambda *_, **_1: 1
31 ) # pragma: no cover
32 VultureItem.fspath = "path/test.py"
33 item = VultureItem.from_parent(
34 Mock(), fspath=Mock()
35 )
36 item.session = Mock()
37 return item
40@patch("pytest_vulture.item.pytest.File.__init__")
41@patch("pytest_vulture.item.pytest.Item.__init__")
42class TestExportLogstashSyslogFactory:
43 """
44 Tests ExportLogstashSyslogFactory
45 """
46 __caller: VultureItem
48 @pytest.fixture(autouse=True)
49 def mock_response(self, mocker):
50 """
51 Get the mocked class
52 """
53 self.__caller = mocker
55 def test_reportinfo(self, *_):
56 """
57 Tests VultureCall.reportinfo
58 """
59 _, value, _ = self.__caller.reportinfo()
60 assert value == -1
62 def test_runtest(self, *_):
63 """
64 Tests VultureCall.runtest
65 """
66 self.__caller.session.vulture.check_error.return_value = "", ""
67 self.__caller.runtest()
68 self.__caller.session.vulture.check_error.return_value = "message", ""
69 with pytest.raises(VultureError):
70 self.__caller.runtest()
72 @patch("pytest_vulture.item.pytest.Item.repr_failure")
73 def test_repr_failure(self, repr_failure, *_):
74 """
75 Tests VultureCall.repr_failure
76 """
77 self.__caller.session.vulture.check_error.return_value = "", ""
78 exc_info = Mock()
79 exc_info.value.message = "1"
80 exc_info.errisinstance.return_value = True
81 assert self.__caller.repr_failure(exc_info) == "1"
82 assert repr_failure.called is False
84 exc_info.errisinstance.return_value = False
85 self.__caller.repr_failure(exc_info)
86 assert repr_failure.called is True