[issue32071] Add py.test-like "-k" test selection to unittest

Antoine Pitrou report at bugs.python.org
Mon Nov 20 18:32:44 EST 2017


Antoine Pitrou <pitrou at free.fr> added the comment:

Le 21/11/2017 à 00:23, Jonas H. a écrit :
> 
> - The loader code really only deals with loading (i.e., finding + importing) tests. Yes it expects a file pattern like "test*.py" for identifying test case files. But apart from that it didn't "feel" right to put name based selection there.

Take a look at TestLoader.loadTestsFromName().  It does much more than
look up test files, it can also look up individual classes or methods.

> - In py.test you'll get a console output like "5 tests passed, 1 test failed, 12 tests deselected". We can't get anything similar without making bigger changes to the test loader, runner, etc. code. Using skip() we at least have some info on "skipped" tests, although they're technically not skipped.

I'm not sure what the point of displaying the number of "deselected"
tests is: that information doesn't sound very useful in itself.

But in any case, marking them skipped feels wrong to me.  Most often,
skipping a test is an indication that the current system is not fit to
run it (such as not enough RAM, or lacking a third-party library, or
being the wrong OS entirely).

> Are you still saying this should go to the test loader?

IMHO, yes.  Looking at your posted implementation, at least I don't
think TestSuite is the place for it.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32071>
_______________________________________


More information about the Python-bugs-list mailing list