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

2017-11-28 Thread Antoine Pitrou
Antoine Pitrou added the comment: New changeset 4d193bcc2560b824389e4d98d9d8b9b34e33dbaf by Antoine Pitrou (Jonas Haag) in branch 'master': bpo-32071: Fix regression and add What's New entry (#4589)

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

2017-11-27 Thread Jonas H.
Jonas H. added the comment: https://github.com/python/cpython/pull/4589 - Add 3.7 What's New entry - Fix regression (thanks Tim for the report) -- ___ Python tracker

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

2017-11-27 Thread Jonas H.
Change by Jonas H. : -- pull_requests: +4513 ___ Python tracker ___ ___ Python-bugs-list

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

2017-11-27 Thread Antoine Pitrou
Antoine Pitrou added the comment: > @Core devs: Should I revert to original behaviour with the order of the > prefix check and the getattr() call, and add a regression test that > guarantees this behaviour? Yes, that sounds reasonable to me. --

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

2017-11-27 Thread Jonas H.
Jonas H. added the comment: Ah, the problem isn't that it's running getattr() on test methods, but that it runs getattr() on all methods. Former code: attrname.startswith(prefix) and \ callable(getattr(testCaseClass, attrname)) New code: testFunc =

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

2017-11-27 Thread Tim Graham
Tim Graham added the comment: This is appearing as a backwards incompatible change for Django because test case class attributes are now evaluated at load time before setUpClass runs (which initializes some things that those class attributes use). It's possible to adapt

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

2017-11-27 Thread Jonas H.
Jonas H. added the comment: Sure! -- ___ Python tracker ___ ___ Python-bugs-list mailing

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

2017-11-27 Thread STINNER Victor
STINNER Victor added the comment: IMHO it's a big enhancement for the base unittest test runner and deserves to be documend in What's New in Python 3.7! Jonas: do you want to write a PR to patch Doc/whatsnew/3.7.rst? --

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

2017-11-25 Thread Antoine Pitrou
Antoine Pitrou added the comment: The enhancement is now pushed to git master. Thank you Jonas for contributing this! -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker

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

2017-11-25 Thread Antoine Pitrou
Antoine Pitrou added the comment: New changeset 5b48dc638b7405fd9bde4d854bf477dfeaaddf44 by Antoine Pitrou (Jonas Haag) in branch 'master': bpo-32071: Add unittest -k option (#4496) https://github.com/python/cpython/commit/5b48dc638b7405fd9bde4d854bf477dfeaaddf44 --

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

2017-11-21 Thread Jonas H.
Jonas H. added the comment: Interesting, Victor. I've had a look at the code you mentioned, but I'm afraid it doesn't really make sense to re-use any of the code. Here's a new patch, implemented in the loader as suggested by Antoine, and with tests. I'm happy to write

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

2017-11-20 Thread STINNER Victor
STINNER Victor added the comment: The internal Python test runner "regrtest" already implements the feature as the -m MATCH option and --matchfile FILENAME option. It's implemented in test.support._match_file(). See bpo-31324 for a recent issue on this feature:

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

2017-11-20 Thread Antoine Pitrou
Antoine Pitrou added the comment: If it helps, think of TestLoader as collecting tests, rather than simply loading Python modules. -- ___ Python tracker

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

2017-11-20 Thread Antoine Pitrou
Antoine Pitrou 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

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

2017-11-20 Thread Jonas H.
Jonas H. added the comment: > > 3) Is the approach of dynamically wrapping 'skip()' around to-be-skipped > > test cases OK? > I think this is the wrong approach. A test that isn't selected shouldn't be > skipped, it should not appear in the output at all. Another reason

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

2017-11-20 Thread Antoine Pitrou
Antoine Pitrou added the comment: First, I should clarify that I'm not a unittest maintainer. However, as far as I can tell, the maintainers have not been very active lately. Also, this is a reasonably simple enhancement (at least conceptually), so I think can do without a

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

2017-11-20 Thread Jonas H.
Jonas H. added the comment: Thanks Antoine. I will need some guidance as to what are the correct places to make these changes. I'm not quite sure about the abstractions here (runner, loader, suite, case, etc.) My PoC (see GitHub link in first post) uses a TestSuite

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

2017-11-18 Thread Antoine Pitrou
Antoine Pitrou added the comment: I think this would be a useful enhancement. Feel free to open a PR. I haven't looked at your implementation, but you'll also need to add tests for it. -- nosy: +ezio.melotti, michael.foord, pitrou, rbcollins stage: -> needs patch

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

2017-11-18 Thread Jonas H.
Jonas H. added the comment: Just to be clear, the current implementation is limited to substring matches. It doesn't support py.test like "and/or" combinators. (Actually, py.test uses 'eval' to support arbitrary patterns.) So say we have test case SomeClass test_foo

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

2017-11-18 Thread Jonas H.
New submission from Jonas H. : I'd like to add test selection based on parts of the test class/method name to unittest. Similar to py.test's "-k" option: https://docs.pytest.org/en/latest/example/markers.html#using-k-expr-to-select-tests-based-on-their-name Here's a proof of