facebook / facebook/TestSlide

I'm unable to mock inherited methods in a subclass when the parent is also mocked

Abierto
#218 1 comentario 0 reacciones 0 asignados Ver en GitHub
bug
Lenguaje dominante
Python
Estrellas
149
Forks
62
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

**I'm using `TestSlide` version:** 2.5.7

**Given:** https://gist.github.com/nsheridan/a08dc79a84cc2974710b7a02b78ff77b

**When I run:**

```
% testslide test.py
```

**I expected this to happen:**
The test `test_parent_and_child_no_override` should pass

**But, instead this happened:**
When both the child and parent classes are mocked I get a `NonExistentAttribute` exception when I attempt to mock a non-overridden method in the child class:
```
% testslide test.py
test.TestThing
test_child
test_parent
test_parent_and_child_no_override: NonExistentAttribute: 'a_method' can not be set.
test_parent_and_child_no_override_careful_ordering
test_parent_and_child_override

Failures:

1) test.TestThing: test_parent_and_child_no_override
1) NonExistentAttribute: 'a_method' can not be set.
template class does not have this attribute so the mock can not have it as well.
See also: 'runtime_attrs' at StrictMock.__init__.
File "/Users/nsheridan/homebrew/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py", line 119, in __exit__
next(self.gen)
File "/Users/nsheridan/homebrew/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/case.py", line 59, in testPartExecutor
yield
File "/Users/nsheridan/homebrew/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/case.py", line 628, in run
testMethod()
File "test.py", line 38, in test_parent_and_child_no_override
self.mock_callable(achild, "a_method").to_return_value(None)

Finished 5 example(s) in 0.2s: .
Successful: 4
Failed: 1
```
As you can see from the example, it is possible to
* mock a method in a child class before the parent is mocked
* mock a method in a child class after the parent is mocked *if* the method is overridden in the child

However if the parent and child classes are both mocked it is not possible to mock non-overridden methods in the child class

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.