facebook / facebook/TestSlide

Fix TestCase loading with nested classes

Open
#51 0 comments 0 reactions 0 assignees View on GitHub
bug help wanted Python Unittest
Dominant language
Python
Stars
149
Forks
62
PR merge metrics
No merged PRs in 30d

Description

TestSlide loads TestCase classes using [this logic](https://github.com/facebookincubator/TestSlide/blob/b2d2ef9c288082b476332938bfc1d486abb0137e/testslide/cli.py#L59-L63). Upstream Python, does it [like this](https://github.com/python/cpython/blob/fd628cf5adaeee73eab579393cdff71c8f70cdf2/Lib/unittest/loader.py#L121-L124). This means, that If the module has this:

```python
class Outer:
class Inner(TestCase):
def test_something(self):
pass
```

Python won't consider `Inner.test_something` as part of the test, but TestSlide will.

This can be easily fixed by refactoring the logic at TestSlide's side to match Python's, however, it won't cover other cases such as [`load_tests()`](https://github.com/python/cpython/blob/fd628cf5adaeee73eab579393cdff71c8f70cdf2/Lib/unittest/loader.py#L126-L130).

The proper fix for this, is to use Python's [`TestLoader`](https://github.com/python/cpython/blob/fd628cf5adaeee73eab579393cdff71c8f70cdf2/Lib/unittest/loader.py#L66) in the same fashion as Python unittent [does form its CLI](https://github.com/python/cpython/blob/fd628cf5adaeee73eab579393cdff71c8f70cdf2/Lib/unittest/main.py#L156).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.