Create a SubRequest based on "self" and call the execute method of the given FixtureDef object. This will force the FixtureDef object to throw away any previous results and compute a new fixture value, which will be stored into the FixtureDef object itself.
(self, fixturedef: "FixtureDef[object]")
| 621 | return values |
| 622 | |
| 623 | def _compute_fixture_value(self, fixturedef: "FixtureDef[object]") -> None: |
| 624 | """Create a SubRequest based on "self" and call the execute method |
| 625 | of the given FixtureDef object. |
| 626 | |
| 627 | This will force the FixtureDef object to throw away any previous |
| 628 | results and compute a new fixture value, which will be stored into |
| 629 | the FixtureDef object itself. |
| 630 | """ |
| 631 | # prepare a subrequest object before calling fixture function |
| 632 | # (latter managed by fixturedef) |
| 633 | argname = fixturedef.argname |
| 634 | funcitem = self._pyfuncitem |
| 635 | scope = fixturedef._scope |
| 636 | try: |
| 637 | param = funcitem.callspec.getparam(argname) |
| 638 | except (AttributeError, ValueError): |
| 639 | param = NOTSET |
| 640 | param_index = 0 |
| 641 | has_params = fixturedef.params is not None |
| 642 | fixtures_not_supported = getattr(funcitem, "nofuncargs", False) |
| 643 | if has_params and fixtures_not_supported: |
| 644 | msg = ( |
| 645 | "{name} does not support fixtures, maybe unittest.TestCase subclass?\n" |
| 646 | "Node id: {nodeid}\n" |
| 647 | "Function type: {typename}" |
| 648 | ).format( |
| 649 | name=funcitem.name, |
| 650 | nodeid=funcitem.nodeid, |
| 651 | typename=type(funcitem).__name__, |
| 652 | ) |
| 653 | fail(msg, pytrace=False) |
| 654 | if has_params: |
| 655 | frame = inspect.stack()[3] |
| 656 | frameinfo = inspect.getframeinfo(frame[0]) |
| 657 | source_path = absolutepath(frameinfo.filename) |
| 658 | source_lineno = frameinfo.lineno |
| 659 | try: |
| 660 | source_path_str = str( |
| 661 | source_path.relative_to(funcitem.config.rootpath) |
| 662 | ) |
| 663 | except ValueError: |
| 664 | source_path_str = str(source_path) |
| 665 | msg = ( |
| 666 | "The requested fixture has no parameter defined for test:\n" |
| 667 | " {}\n\n" |
| 668 | "Requested fixture '{}' defined in:\n{}" |
| 669 | "\n\nRequested here:\n{}:{}".format( |
| 670 | funcitem.nodeid, |
| 671 | fixturedef.argname, |
| 672 | getlocation(fixturedef.func, funcitem.config.rootpath), |
| 673 | source_path_str, |
| 674 | source_lineno, |
| 675 | ) |
| 676 | ) |
| 677 | fail(msg, pytrace=False) |
| 678 | else: |
| 679 | param_index = funcitem.callspec.indices[argname] |
| 680 | # If a parametrize invocation set a scope it will override |
no test coverage detected