Title: Allow access to unittest.TestSuite tests
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.7
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, ezio.melotti, lbenezriravin, michael.foord, rbcollins
Priority: normal Keywords:

Created on 2018-11-19 19:25 by lbenezriravin, last changed 2018-11-26 21:56 by brett.cannon. This issue is now closed.

Messages (4)
msg330111 - (view) Author: Lihu (lbenezriravin) Date: 2018-11-19 19:25
I would like to have access to the list of tests in a TestSuite object.
Currently there are two ways of doing this: I can access the protected attribute `_tests`, or I can iterate over the TestSuite and re-create data that I already have. The former option isn't part of the public API and makes mypy mad, and the latter seems redundant. Could we get a public property or getter for the internal test list (or a more appropriate implementation if necessary)?
msg330152 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2018-11-20 20:34
I don't quite follow what you're after as it sounds the same as calling `list(test_suite)`. Am I missing something or are you just trying to avoid the list creation?
msg330361 - (view) Author: Lihu (lbenezriravin) Date: 2018-11-23 19:58
Sorry, I guess some context might be helpful. I'm writing a program that links unittest-based tests with a third-party test tracking/reporting system. Said third-party software has a concept of test suites/cases that doesn't align 1:1 with unittest, so I need to manipulate the unittest objects a bit to get them to connect smoothly.

`list(test_suite)` is a bit clunky for me, since I'm already copying said list in order to do my manipulation. So I end up with expressions like:

my_cases = list(my_custom_generator(list(test_suite)))

Certainly not the end of the world, and it works just fine, but it's redundant and I need to do it a lot. I realize that `list(iterator)` is an increasingly common idiom in python 3, but I thought I'd throw this usecase out there for your consideration.
msg330471 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2018-11-26 21:56
Gotcha, thanks for the clarification!

Unfortunately I don't think we will be able to accommodate your feature request. It's duplicating an API to simply save calling list() which is the idiomatic way to convert an iterable into a concrete sequence. And providing direct access to the list would be either unittest.TestCase-specific or all subclasses would then have to start supporting it.
Date User Action Args
2018-11-26 21:56:54brett.cannonsetstatus: open -> closed
resolution: rejected
messages: + msg330471

stage: resolved
2018-11-23 19:58:22lbenezriravinsetmessages: + msg330361
2018-11-20 20:34:03brett.cannonsetnosy: + brett.cannon
messages: + msg330152
2018-11-19 19:28:53lbenezriravinsetnosy: + rbcollins, ezio.melotti, michael.foord
2018-11-19 19:25:49lbenezriravincreate