(self)
| 909 | self.msg = msg |
| 910 | |
| 911 | def formatrepr(self) -> FixtureLookupErrorRepr: |
| 912 | tblines: list[str] = [] |
| 913 | addline = tblines.append |
| 914 | stack = [self.request._pyfuncitem.obj] |
| 915 | stack.extend(map(lambda x: x.func, self.fixturestack)) |
| 916 | msg = self.msg |
| 917 | if msg is not None and len(stack) > 1: |
| 918 | # The last fixture raise an error, let's present |
| 919 | # it at the requesting side. |
| 920 | stack = stack[:-1] |
| 921 | for function in stack: |
| 922 | fspath, lineno = getfslineno(function) |
| 923 | try: |
| 924 | lines, _ = inspect.getsourcelines(get_real_func(function)) |
| 925 | except (OSError, IndexError, TypeError): |
| 926 | error_msg = "file %s, line %s: source code not available" |
| 927 | addline(error_msg % (fspath, lineno + 1)) |
| 928 | else: |
| 929 | addline(f"file {fspath}, line {lineno + 1}") |
| 930 | for i, line in enumerate(lines): |
| 931 | line = line.rstrip() |
| 932 | addline(" " + line) |
| 933 | if line.lstrip().startswith("def"): |
| 934 | break |
| 935 | |
| 936 | if msg is None: |
| 937 | fm = self.request._fixturemanager |
| 938 | available = set() |
| 939 | parent = self.request._pyfuncitem.parent |
| 940 | assert parent is not None |
| 941 | for name, fixturedefs in fm._arg2fixturedefs.items(): |
| 942 | faclist = list(fm._matchfactories(fixturedefs, parent)) |
| 943 | if faclist: |
| 944 | available.add(name) |
| 945 | if self.argname in available: |
| 946 | msg = ( |
| 947 | f" recursive dependency involving fixture '{self.argname}' detected" |
| 948 | ) |
| 949 | else: |
| 950 | msg = f"fixture '{self.argname}' not found" |
| 951 | msg += "\n available fixtures: {}".format(", ".join(sorted(available))) |
| 952 | msg += "\n use 'pytest --fixtures [testpath]' for help on them." |
| 953 | |
| 954 | return FixtureLookupErrorRepr(fspath, lineno, tblines, msg, self.argname) |
| 955 | |
| 956 | |
| 957 | class FixtureLookupErrorRepr(TerminalRepr): |
no test coverage detected