facebook / facebook/TestSlide

RecursionError when inspect.getfullargspec is mocked

Offen
#160 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
bug help wanted mock(_async)_callable
Vorherrschende Sprache
Python
Sterne
149
Forks
62
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

Given:

```python
import inspect
import subprocess
from testslide.dsl import context

class SomeClass:
@staticmethod
def method():
inspect.getfullargspec(subprocess.Popen.__init__)

@context
def top(context):
@context.example
def repro(self):
self.mock_callable(inspect, "getfullargspec").to_call_original()
SomeClass.method()
```

When:

```
$ python -m testslide.cli --show-testslide-stack-trace repro.py
```

Then:

```
top
repro: RecursionError: maximum recursion depth exceeded while calling a Python object

Failures:

1) top: repro
1) RecursionError: maximum recursion depth exceeded while calling a Python object
File "testslide/runner.py", line 578, in run
self._run_example(example)
File "testslide/runner.py", line 562, in _run_example
_ExampleRunner(example, self.formatter).run()
File "testslide/__init__.py", line 441, in run
self._sync_run_all_hooks_and_example(context_data)
File "testslide/__init__.py", line 413, in _sync_run_all_hooks_and_example
aggregated_exceptions.raise_correct_exception()
File "testslide/__init__.py", line 199, in raise_correct_exception
raise self.exceptions[0]
File "testslide/__init__.py", line 183, in catch
yield
File "testslide/__init__.py", line 404, in _sync_run_all_hooks_and_example
self._fail_if_coroutine_function(self.example.code, context_data)
File "testslide/__init__.py", line 376, in _fail_if_coroutine_function
return func(*args, **kwargs)
File "repro.py", line 15, in repro
SomeClass.method()
File "repro.py", line 8, in method
inspect.getfullargspec(subprocess.Popen.__init__)
File "testslide/lib.py", line 131, in with_sig_check
_validate_function_signature(callable_template, args, kwargs)
File "testslide/lib.py", line 56, in _validate_function_signature
argspec = inspect.getfullargspec(callable_template)
File "testslide/lib.py", line 131, in with_sig_check
_validate_function_signature(callable_template, args, kwargs)
File "testslide/lib.py", line 56, in _validate_function_signature
argspec = inspect.getfullargspec(callable_template)
(last 2 lines repeat a lot)
File "testslide/lib.py", line 125, in with_sig_check
signature.bind(*args, **kwargs)
File "/home/fornellas/.pyenv/versions/3.8.0/lib/python3.8/inspect.py", line 3025, in bind
return self._bind(args, kwargs)
File "/home/fornellas/.pyenv/versions/3.8.0/lib/python3.8/inspect.py", line 2892, in _bind
arguments = OrderedDict()

Finished 1 example(s) in 0.8s: .
Failed: 1
```

TestSlide uses `inspect.getfullargspec` internally, and somehow, the mock is interfering with it.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.