MCPcopy Index your code
hub / github.com/pytest-dev/pytest / test_function_instance

Function test_function_instance

testing/python/integration.py:428–465  ·  view source on GitHub ↗
(pytester: Pytester)

Source from the content-addressed store, hash-verified

426
427
428def test_function_instance(pytester: Pytester) -> None:
429 items = pytester.getitems(
430 """
431 def test_func(): pass
432
433 class TestIt:
434 def test_method(self): pass
435
436 @classmethod
437 def test_class(cls): pass
438
439 @staticmethod
440 def test_static(): pass
441 """
442 )
443 assert len(items) == 4
444
445 assert isinstance(items[0], Function)
446 assert items[0].name == "test_func"
447 assert items[0].instance is None
448
449 assert isinstance(items[1], Function)
450 assert items[1].name == "test_method"
451 assert items[1].instance is not None
452 assert items[1].instance.__class__.__name__ == "TestIt"
453
454 # Even class and static methods get an instance!
455 # This is the instance used for bound fixture methods, which
456 # class/staticmethod tests are perfectly able to request.
457 assert isinstance(items[2], Function)
458 assert items[2].name == "test_class"
459 assert items[2].instance is not None
460
461 assert isinstance(items[3], Function)
462 assert items[3].name == "test_static"
463 assert items[3].instance is not None
464
465 assert items[1].instance is not items[2].instance is not items[3].instance

Callers

nothing calls this directly

Calls 1

getitemsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…