2024-01-28 21:12:42 +08:00
|
|
|
# mypy: allow-untyped-defs
|
2020-07-31 14:46:56 +08:00
|
|
|
from _pytest._code import getfslineno
|
2020-11-26 20:50:44 +08:00
|
|
|
from _pytest.fixtures import getfixturemarker
|
2020-12-10 13:47:58 +08:00
|
|
|
from _pytest.pytester import Pytester
|
2021-11-13 20:03:44 +08:00
|
|
|
from _pytest.python import Function
|
2013-10-12 21:39:22 +08:00
|
|
|
import pytest
|
2015-11-27 22:43:01 +08:00
|
|
|
|
2012-11-06 18:04:11 +08:00
|
|
|
|
2020-05-01 19:40:17 +08:00
|
|
|
def test_wrapped_getfslineno() -> None:
|
2013-11-20 06:22:27 +08:00
|
|
|
def func():
|
|
|
|
pass
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2013-11-20 06:22:27 +08:00
|
|
|
def wrap(f):
|
2020-05-01 19:40:17 +08:00
|
|
|
func.__wrapped__ = f # type: ignore
|
|
|
|
func.patchings = ["qwe"] # type: ignore
|
2013-11-20 06:22:27 +08:00
|
|
|
return func
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2013-11-20 06:22:27 +08:00
|
|
|
@wrap
|
|
|
|
def wrapped_func(x, y, z):
|
|
|
|
pass
|
2018-05-23 22:48:46 +08:00
|
|
|
|
2020-07-31 14:46:56 +08:00
|
|
|
fs, lineno = getfslineno(wrapped_func)
|
|
|
|
fs2, lineno2 = getfslineno(wrap)
|
2013-11-20 06:22:27 +08:00
|
|
|
assert lineno > lineno2, "getfslineno does not unwrap correctly"
|
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class TestMockDecoration:
|
2020-05-01 19:40:17 +08:00
|
|
|
def test_wrapped_getfuncargnames(self) -> None:
|
2012-11-06 18:04:11 +08:00
|
|
|
from _pytest.compat import getfuncargnames
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2012-11-06 18:04:11 +08:00
|
|
|
def wrap(f):
|
|
|
|
def func():
|
|
|
|
pass
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2020-05-01 19:40:17 +08:00
|
|
|
func.__wrapped__ = f # type: ignore
|
2012-11-06 18:04:11 +08:00
|
|
|
return func
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2012-11-06 18:04:11 +08:00
|
|
|
@wrap
|
|
|
|
def f(x):
|
|
|
|
pass
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2017-11-04 23:17:20 +08:00
|
|
|
values = getfuncargnames(f)
|
|
|
|
assert values == ("x",)
|
2012-11-06 18:04:11 +08:00
|
|
|
|
2019-07-15 23:23:59 +08:00
|
|
|
def test_getfuncargnames_patching(self):
|
|
|
|
from unittest.mock import patch
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2012-11-06 18:04:11 +08:00
|
|
|
from _pytest.compat import getfuncargnames
|
2024-01-31 03:34:23 +08:00
|
|
|
|
2019-07-15 23:23:59 +08:00
|
|
|
class T:
|
|
|
|
def original(self, x, y, z):
|
2012-11-06 18:04:11 +08:00
|
|
|
pass
|
2018-05-23 22:48:46 +08:00
|
|
|
|
2019-07-15 23:23:59 +08:00
|
|
|
@patch.object(T, "original")
|
2012-11-06 18:04:11 +08:00
|
|
|
def f(x, y, z):
|
|
|
|
pass
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2017-11-04 23:17:20 +08:00
|
|
|
values = getfuncargnames(f)
|
|
|
|
assert values == ("y", "z")
|
2012-11-06 18:04:11 +08:00
|
|
|
|
2020-12-10 13:47:58 +08:00
|
|
|
def test_unittest_mock(self, pytester: Pytester) -> None:
|
|
|
|
pytester.makepyfile(
|
2012-11-06 18:04:11 +08:00
|
|
|
"""
|
|
|
|
import unittest.mock
|
|
|
|
class T(unittest.TestCase):
|
|
|
|
@unittest.mock.patch("os.path.abspath")
|
|
|
|
def test_hello(self, abspath):
|
|
|
|
import os
|
|
|
|
os.path.abspath("hello")
|
|
|
|
abspath.assert_any_call("hello")
|
|
|
|
"""
|
|
|
|
)
|
2020-12-10 13:47:58 +08:00
|
|
|
reprec = pytester.inline_run()
|
2012-11-06 18:04:11 +08:00
|
|
|
reprec.assertoutcome(passed=1)
|
|
|
|
|
2020-12-10 13:47:58 +08:00
|
|
|
def test_unittest_mock_and_fixture(self, pytester: Pytester) -> None:
|
|
|
|
pytester.makepyfile(
|
2014-07-26 23:26:18 +08:00
|
|
|
"""
|
|
|
|
import os.path
|
|
|
|
import unittest.mock
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def inject_me():
|
|
|
|
pass
|
|
|
|
|
|
|
|
@unittest.mock.patch.object(os.path, "abspath",
|
|
|
|
new=unittest.mock.MagicMock)
|
|
|
|
def test_hello(inject_me):
|
|
|
|
import os
|
|
|
|
os.path.abspath("hello")
|
|
|
|
"""
|
|
|
|
)
|
2020-12-10 13:47:58 +08:00
|
|
|
reprec = pytester.inline_run()
|
2014-07-26 23:26:18 +08:00
|
|
|
reprec.assertoutcome(passed=1)
|
|
|
|
|
2020-12-10 13:47:58 +08:00
|
|
|
def test_unittest_mock_and_pypi_mock(self, pytester: Pytester) -> None:
|
2018-02-13 01:41:00 +08:00
|
|
|
pytest.importorskip("mock", "1.0.1")
|
2020-12-10 13:47:58 +08:00
|
|
|
pytester.makepyfile(
|
2018-02-13 01:41:00 +08:00
|
|
|
"""
|
|
|
|
import mock
|
|
|
|
import unittest.mock
|
|
|
|
class TestBoth(object):
|
|
|
|
@unittest.mock.patch("os.path.abspath")
|
|
|
|
def test_hello(self, abspath):
|
|
|
|
import os
|
|
|
|
os.path.abspath("hello")
|
|
|
|
abspath.assert_any_call("hello")
|
|
|
|
|
|
|
|
@mock.patch("os.path.abspath")
|
|
|
|
def test_hello_mock(self, abspath):
|
|
|
|
import os
|
|
|
|
os.path.abspath("hello")
|
|
|
|
abspath.assert_any_call("hello")
|
|
|
|
"""
|
|
|
|
)
|
2020-12-10 13:47:58 +08:00
|
|
|
reprec = pytester.inline_run()
|
2018-02-13 01:41:00 +08:00
|
|
|
reprec.assertoutcome(passed=2)
|
|
|
|
|
2020-12-10 13:47:58 +08:00
|
|
|
def test_mock_sentinel_check_against_numpy_like(self, pytester: Pytester) -> None:
|
2019-07-20 03:59:43 +08:00
|
|
|
"""Ensure our function that detects mock arguments compares against sentinels using
|
|
|
|
identity to circumvent objects which can't be compared with equality against others
|
|
|
|
in a truth context, like with numpy arrays (#5606).
|
|
|
|
"""
|
2020-12-10 13:47:58 +08:00
|
|
|
pytester.makepyfile(
|
2019-07-20 03:59:43 +08:00
|
|
|
dummy="""
|
|
|
|
class NumpyLike:
|
|
|
|
def __init__(self, value):
|
|
|
|
self.value = value
|
|
|
|
def __eq__(self, other):
|
|
|
|
raise ValueError("like numpy, cannot compare against others for truth")
|
|
|
|
FOO = NumpyLike(10)
|
|
|
|
"""
|
|
|
|
)
|
2020-12-10 13:47:58 +08:00
|
|
|
pytester.makepyfile(
|
2019-07-20 03:59:43 +08:00
|
|
|
"""
|
|
|
|
from unittest.mock import patch
|
|
|
|
import dummy
|
|
|
|
class Test(object):
|
|
|
|
@patch("dummy.FOO", new=dummy.NumpyLike(50))
|
|
|
|
def test_hello(self):
|
|
|
|
assert dummy.FOO.value == 50
|
|
|
|
"""
|
|
|
|
)
|
2020-12-10 13:47:58 +08:00
|
|
|
reprec = pytester.inline_run()
|
2019-07-20 03:59:43 +08:00
|
|
|
reprec.assertoutcome(passed=1)
|
|
|
|
|
2020-12-10 13:47:58 +08:00
|
|
|
def test_mock(self, pytester: Pytester) -> None:
|
2012-11-06 18:04:11 +08:00
|
|
|
pytest.importorskip("mock", "1.0.1")
|
2020-12-10 13:47:58 +08:00
|
|
|
pytester.makepyfile(
|
2012-11-06 18:04:11 +08:00
|
|
|
"""
|
|
|
|
import os
|
|
|
|
import unittest
|
|
|
|
import mock
|
|
|
|
|
|
|
|
class T(unittest.TestCase):
|
|
|
|
@mock.patch("os.path.abspath")
|
|
|
|
def test_hello(self, abspath):
|
|
|
|
os.path.abspath("hello")
|
|
|
|
abspath.assert_any_call("hello")
|
2014-03-04 02:36:59 +08:00
|
|
|
def mock_basename(path):
|
|
|
|
return "mock_basename"
|
2012-11-06 18:04:11 +08:00
|
|
|
@mock.patch("os.path.abspath")
|
|
|
|
@mock.patch("os.path.normpath")
|
2014-03-27 02:37:49 +08:00
|
|
|
@mock.patch("os.path.basename", new=mock_basename)
|
2021-02-21 21:10:00 +08:00
|
|
|
def test_someting(normpath, abspath, tmp_path):
|
2012-11-06 18:04:11 +08:00
|
|
|
abspath.return_value = "this"
|
|
|
|
os.path.normpath(os.path.abspath("hello"))
|
|
|
|
normpath.assert_any_call("this")
|
2014-03-27 02:37:49 +08:00
|
|
|
assert os.path.basename("123") == "mock_basename"
|
2012-11-06 18:04:11 +08:00
|
|
|
"""
|
|
|
|
)
|
2020-12-10 13:47:58 +08:00
|
|
|
reprec = pytester.inline_run()
|
2012-11-06 18:04:11 +08:00
|
|
|
reprec.assertoutcome(passed=2)
|
2013-12-03 18:23:22 +08:00
|
|
|
calls = reprec.getcalls("pytest_runtest_logreport")
|
|
|
|
funcnames = [
|
|
|
|
call.report.location[2] for call in calls if call.report.when == "call"
|
2017-07-17 07:25:07 +08:00
|
|
|
]
|
2013-12-03 18:23:22 +08:00
|
|
|
assert funcnames == ["T.test_hello", "test_someting"]
|
2013-04-22 16:35:48 +08:00
|
|
|
|
2020-12-10 13:47:58 +08:00
|
|
|
def test_mock_sorting(self, pytester: Pytester) -> None:
|
2013-11-20 06:22:27 +08:00
|
|
|
pytest.importorskip("mock", "1.0.1")
|
2020-12-10 13:47:58 +08:00
|
|
|
pytester.makepyfile(
|
2013-11-20 06:22:27 +08:00
|
|
|
"""
|
|
|
|
import os
|
|
|
|
import mock
|
|
|
|
|
|
|
|
@mock.patch("os.path.abspath")
|
|
|
|
def test_one(abspath):
|
|
|
|
pass
|
|
|
|
@mock.patch("os.path.abspath")
|
|
|
|
def test_two(abspath):
|
|
|
|
pass
|
|
|
|
@mock.patch("os.path.abspath")
|
|
|
|
def test_three(abspath):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
)
|
2020-12-10 13:47:58 +08:00
|
|
|
reprec = pytester.inline_run()
|
2013-11-20 06:22:27 +08:00
|
|
|
calls = reprec.getreports("pytest_runtest_logreport")
|
|
|
|
calls = [x for x in calls if x.when == "call"]
|
|
|
|
names = [x.nodeid.split("::")[-1] for x in calls]
|
|
|
|
assert names == ["test_one", "test_two", "test_three"]
|
|
|
|
|
2020-12-10 13:47:58 +08:00
|
|
|
def test_mock_double_patch_issue473(self, pytester: Pytester) -> None:
|
2014-04-10 18:46:27 +08:00
|
|
|
pytest.importorskip("mock", "1.0.1")
|
2020-12-10 13:47:58 +08:00
|
|
|
pytester.makepyfile(
|
2014-04-08 18:50:13 +08:00
|
|
|
"""
|
|
|
|
from mock import patch
|
|
|
|
from pytest import mark
|
|
|
|
|
|
|
|
@patch('os.getcwd')
|
|
|
|
@patch('os.path')
|
2014-04-10 18:58:10 +08:00
|
|
|
@mark.slow
|
2017-02-17 02:41:51 +08:00
|
|
|
class TestSimple(object):
|
2014-04-08 18:50:13 +08:00
|
|
|
def test_simple_thing(self, mock_path, mock_getcwd):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
)
|
2020-12-10 13:47:58 +08:00
|
|
|
reprec = pytester.inline_run()
|
2014-04-10 18:46:27 +08:00
|
|
|
reprec.assertoutcome(passed=1)
|
2014-04-08 18:50:13 +08:00
|
|
|
|
2013-04-22 16:35:48 +08:00
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class TestReRunTests:
|
2020-12-10 13:47:58 +08:00
|
|
|
def test_rerun(self, pytester: Pytester) -> None:
|
|
|
|
pytester.makeconftest(
|
2013-04-22 16:35:48 +08:00
|
|
|
"""
|
|
|
|
from _pytest.runner import runtestprotocol
|
|
|
|
def pytest_runtest_protocol(item, nextitem):
|
|
|
|
runtestprotocol(item, log=False, nextitem=nextitem)
|
|
|
|
runtestprotocol(item, log=True, nextitem=nextitem)
|
|
|
|
"""
|
|
|
|
)
|
2020-12-10 13:47:58 +08:00
|
|
|
pytester.makepyfile(
|
2013-04-22 16:35:48 +08:00
|
|
|
"""
|
|
|
|
import pytest
|
|
|
|
count = 0
|
|
|
|
req = None
|
|
|
|
@pytest.fixture
|
|
|
|
def fix(request):
|
|
|
|
global count, req
|
|
|
|
assert request != req
|
|
|
|
req = request
|
2018-11-22 16:15:14 +08:00
|
|
|
print("fix count %s" % count)
|
2013-04-22 16:35:48 +08:00
|
|
|
count += 1
|
|
|
|
def test_fix(fix):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
)
|
2020-12-10 13:47:58 +08:00
|
|
|
result = pytester.runpytest("-s")
|
2013-04-22 16:35:48 +08:00
|
|
|
result.stdout.fnmatch_lines(
|
|
|
|
"""
|
|
|
|
*fix count 0*
|
|
|
|
*fix count 1*
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
result.stdout.fnmatch_lines(
|
|
|
|
"""
|
|
|
|
*2 passed*
|
|
|
|
"""
|
|
|
|
)
|
2013-10-21 19:33:36 +08:00
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2020-05-01 19:40:17 +08:00
|
|
|
def test_pytestconfig_is_session_scoped() -> None:
|
2013-10-21 19:33:36 +08:00
|
|
|
from _pytest.fixtures import pytestconfig
|
2018-05-23 22:48:46 +08:00
|
|
|
|
2020-11-26 20:50:44 +08:00
|
|
|
marker = getfixturemarker(pytestconfig)
|
|
|
|
assert marker is not None
|
2020-05-01 19:40:17 +08:00
|
|
|
assert marker.scope == "session"
|
2014-04-10 18:46:27 +08:00
|
|
|
|
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class TestNoselikeTestAttribute:
|
2020-12-10 13:47:58 +08:00
|
|
|
def test_module_with_global_test(self, pytester: Pytester) -> None:
|
|
|
|
pytester.makepyfile(
|
2014-04-10 18:46:27 +08:00
|
|
|
"""
|
|
|
|
__test__ = False
|
|
|
|
def test_hello():
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
)
|
2020-12-10 13:47:58 +08:00
|
|
|
reprec = pytester.inline_run()
|
2014-04-10 19:37:39 +08:00
|
|
|
assert not reprec.getfailedcollections()
|
2014-04-10 18:46:27 +08:00
|
|
|
calls = reprec.getreports("pytest_runtest_logreport")
|
|
|
|
assert not calls
|
2015-04-18 04:25:35 +08:00
|
|
|
|
2020-12-10 13:47:58 +08:00
|
|
|
def test_class_and_method(self, pytester: Pytester) -> None:
|
|
|
|
pytester.makepyfile(
|
2014-04-10 18:46:27 +08:00
|
|
|
"""
|
|
|
|
__test__ = True
|
|
|
|
def test_func():
|
|
|
|
pass
|
2014-04-10 19:37:39 +08:00
|
|
|
test_func.__test__ = False
|
2014-04-10 18:46:27 +08:00
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class TestSome(object):
|
2014-04-10 18:46:27 +08:00
|
|
|
__test__ = False
|
|
|
|
def test_method(self):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
)
|
2020-12-10 13:47:58 +08:00
|
|
|
reprec = pytester.inline_run()
|
2014-04-10 19:37:39 +08:00
|
|
|
assert not reprec.getfailedcollections()
|
2014-04-10 18:46:27 +08:00
|
|
|
calls = reprec.getreports("pytest_runtest_logreport")
|
|
|
|
assert not calls
|
|
|
|
|
2020-12-10 13:47:58 +08:00
|
|
|
def test_unittest_class(self, pytester: Pytester) -> None:
|
|
|
|
pytester.makepyfile(
|
2014-04-10 18:46:27 +08:00
|
|
|
"""
|
|
|
|
import unittest
|
|
|
|
class TC(unittest.TestCase):
|
|
|
|
def test_1(self):
|
|
|
|
pass
|
|
|
|
class TC2(unittest.TestCase):
|
|
|
|
__test__ = False
|
|
|
|
def test_2(self):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
)
|
2020-12-10 13:47:58 +08:00
|
|
|
reprec = pytester.inline_run()
|
2014-04-10 19:37:39 +08:00
|
|
|
assert not reprec.getfailedcollections()
|
2014-04-10 18:46:27 +08:00
|
|
|
call = reprec.getcalls("pytest_collection_modifyitems")[0]
|
|
|
|
assert len(call.items) == 1
|
|
|
|
assert call.items[0].cls.__name__ == "TC"
|
|
|
|
|
2020-12-10 13:47:58 +08:00
|
|
|
def test_class_with_nasty_getattr(self, pytester: Pytester) -> None:
|
2015-11-30 23:41:13 +08:00
|
|
|
"""Make sure we handle classes with a custom nasty __getattr__ right.
|
|
|
|
|
|
|
|
With a custom __getattr__ which e.g. returns a function (like with a
|
|
|
|
RPC wrapper), we shouldn't assume this meant "__test__ = True".
|
|
|
|
"""
|
|
|
|
# https://github.com/pytest-dev/pytest/issues/1204
|
2020-12-10 13:47:58 +08:00
|
|
|
pytester.makepyfile(
|
2015-11-30 23:41:13 +08:00
|
|
|
"""
|
|
|
|
class MetaModel(type):
|
|
|
|
|
|
|
|
def __getattr__(cls, key):
|
|
|
|
return lambda: None
|
|
|
|
|
|
|
|
|
|
|
|
BaseModel = MetaModel('Model', (), {})
|
|
|
|
|
|
|
|
|
|
|
|
class Model(BaseModel):
|
|
|
|
|
|
|
|
__metaclass__ = MetaModel
|
|
|
|
|
|
|
|
def test_blah(self):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
)
|
2020-12-10 13:47:58 +08:00
|
|
|
reprec = pytester.inline_run()
|
2015-11-30 23:41:13 +08:00
|
|
|
assert not reprec.getfailedcollections()
|
|
|
|
call = reprec.getcalls("pytest_collection_modifyitems")[0]
|
|
|
|
assert not call.items
|
|
|
|
|
2014-10-08 07:11:32 +08:00
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class TestParameterize:
|
2019-04-27 22:25:37 +08:00
|
|
|
"""#351"""
|
|
|
|
|
2020-12-10 13:47:58 +08:00
|
|
|
def test_idfn_marker(self, pytester: Pytester) -> None:
|
|
|
|
pytester.makepyfile(
|
2014-10-08 07:11:32 +08:00
|
|
|
"""
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
def idfn(param):
|
|
|
|
if param == 0:
|
|
|
|
return 'spam'
|
|
|
|
elif param == 1:
|
|
|
|
return 'ham'
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('a,b', [(0, 2), (1, 2)], ids=idfn)
|
|
|
|
def test_params(a, b):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
)
|
2020-12-10 13:47:58 +08:00
|
|
|
res = pytester.runpytest("--collect-only")
|
2014-10-08 07:11:32 +08:00
|
|
|
res.stdout.fnmatch_lines(["*spam-2*", "*ham-2*"])
|
|
|
|
|
2020-12-10 13:47:58 +08:00
|
|
|
def test_idfn_fixture(self, pytester: Pytester) -> None:
|
|
|
|
pytester.makepyfile(
|
2014-10-08 07:11:32 +08:00
|
|
|
"""
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
def idfn(param):
|
|
|
|
if param == 0:
|
|
|
|
return 'spam'
|
|
|
|
elif param == 1:
|
|
|
|
return 'ham'
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
@pytest.fixture(params=[0, 1], ids=idfn)
|
|
|
|
def a(request):
|
|
|
|
return request.param
|
|
|
|
|
|
|
|
@pytest.fixture(params=[1, 2], ids=idfn)
|
|
|
|
def b(request):
|
|
|
|
return request.param
|
|
|
|
|
|
|
|
def test_params(a, b):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
)
|
2020-12-10 13:47:58 +08:00
|
|
|
res = pytester.runpytest("--collect-only")
|
2014-10-08 07:11:32 +08:00
|
|
|
res.stdout.fnmatch_lines(["*spam-2*", "*ham-2*"])
|
2021-11-13 20:03:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
def test_function_instance(pytester: Pytester) -> None:
|
|
|
|
items = pytester.getitems(
|
|
|
|
"""
|
|
|
|
def test_func(): pass
|
2024-03-09 15:08:44 +08:00
|
|
|
|
2021-11-13 20:03:44 +08:00
|
|
|
class TestIt:
|
|
|
|
def test_method(self): pass
|
2024-03-09 15:08:44 +08:00
|
|
|
|
2021-11-13 20:03:44 +08:00
|
|
|
@classmethod
|
|
|
|
def test_class(cls): pass
|
2024-03-09 15:08:44 +08:00
|
|
|
|
2021-11-13 20:03:44 +08:00
|
|
|
@staticmethod
|
|
|
|
def test_static(): pass
|
|
|
|
"""
|
|
|
|
)
|
2022-12-02 23:53:04 +08:00
|
|
|
assert len(items) == 4
|
2024-03-09 15:08:44 +08:00
|
|
|
|
2021-11-13 20:03:44 +08:00
|
|
|
assert isinstance(items[0], Function)
|
|
|
|
assert items[0].name == "test_func"
|
|
|
|
assert items[0].instance is None
|
2024-03-09 15:08:44 +08:00
|
|
|
|
2021-11-13 20:03:44 +08:00
|
|
|
assert isinstance(items[1], Function)
|
|
|
|
assert items[1].name == "test_method"
|
|
|
|
assert items[1].instance is not None
|
|
|
|
assert items[1].instance.__class__.__name__ == "TestIt"
|
2024-03-09 15:08:44 +08:00
|
|
|
|
|
|
|
# Even class and static methods get an instance!
|
|
|
|
# This is the instance used for bound fixture methods, which
|
|
|
|
# class/staticmethod tests are perfectly able to request.
|
|
|
|
assert isinstance(items[2], Function)
|
|
|
|
assert items[2].name == "test_class"
|
|
|
|
assert items[2].instance is not None
|
|
|
|
|
2022-12-02 23:53:04 +08:00
|
|
|
assert isinstance(items[3], Function)
|
|
|
|
assert items[3].name == "test_static"
|
2024-03-09 15:08:44 +08:00
|
|
|
assert items[3].instance is not None
|
|
|
|
|
|
|
|
assert items[1].instance is not items[2].instance is not items[3].instance
|