MCPcopy
hub / github.com/pytest-dev/pytest / _check_fixturedef_without_param

Method _check_fixturedef_without_param

src/_pytest/fixtures.py:731–762  ·  view source on GitHub ↗

Check that this request is allowed to execute this fixturedef without a param.

(self, fixturedef: FixtureDef[object])

Source from the content-addressed store, hash-verified

729 return fixturedef
730
731 def _check_fixturedef_without_param(self, fixturedef: FixtureDef[object]) -> None:
732 """Check that this request is allowed to execute this fixturedef without
733 a param."""
734 funcitem = self._pyfuncitem
735 has_params = fixturedef.params is not None
736 fixtures_not_supported = getattr(funcitem, "nofuncargs", False)
737 if has_params and fixtures_not_supported:
738 msg = (
739 f"{funcitem.name} does not support fixtures, maybe unittest.TestCase subclass?\n"
740 f"Node id: {funcitem.nodeid}\n"
741 f"Function type: {type(funcitem).__name__}"
742 )
743 fail(msg, pytrace=False)
744 if has_params:
745 frame = inspect.stack()[3]
746 frameinfo = inspect.getframeinfo(frame[0])
747 source_path = absolutepath(frameinfo.filename)
748 source_lineno = frameinfo.lineno
749 try:
750 source_path_str = str(source_path.relative_to(funcitem.config.rootpath))
751 except ValueError:
752 source_path_str = str(source_path)
753 location = getlocation(fixturedef.func, funcitem.config.rootpath)
754 msg = (
755 "The requested fixture has no parameter defined for test:\n"
756 f" {funcitem.nodeid}\n\n"
757 f"Requested fixture '{fixturedef.argname}' defined in:\n"
758 f"{location}\n\n"
759 f"Requested here:\n"
760 f"{source_path_str}:{source_lineno}"
761 )
762 fail(msg, pytrace=False)
763
764 def _get_fixturestack(self) -> list[FixtureDef[Any]]:
765 values = [request._fixturedef for request in self._iter_chain()]

Callers 1

Calls 2

absolutepathFunction · 0.90
getlocationFunction · 0.90

Tested by

no test coverage detected