classification
Title: regrtest refleak: implement bisection feature
Type: enhancement Stage: resolved
Components: Tests Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: quentel, serhiy.storchaka, vstinner, yselivanov
Priority: normal Keywords: patch

Created on 2017-02-09 11:46 by vstinner, last changed 2019-05-02 02:52 by miss-islington. This issue is now closed.

Files
File name Uploaded Description Edit
bisect_test.py vstinner, 2017-06-01 20:46
bisect_test.py vstinner, 2017-06-08 15:48
bisect_test.py vstinner, 2017-06-08 15:53
Pull Requests
URL Status Linked Edit
PR 2452 merged vstinner, 2017-06-27 21:51
PR 2513 merged vstinner, 2017-06-30 15:11
PR 2540 merged vstinner, 2017-07-03 10:57
PR 2541 merged vstinner, 2017-07-03 11:30
PR 4522 merged vstinner, 2017-11-23 15:35
PR 7229 merged vstinner, 2018-05-29 22:43
PR 13040 merged xtreak, 2019-05-01 14:40
PR 13051 merged miss-islington, 2019-05-02 02:52
PR 13050 merged miss-islington, 2019-05-02 02:52
Messages (21)
msg287405 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-02-09 11:46
It would be great to be able to list which methods cause a reference leak.

Example right now on the 3.6 branch:
----
$ ./python -m test -R 3:3 test_os 
Run tests sequentially
0:00:00 [1/1] test_os
beginning 6 repetitions
123456
......
test_os leaked [124, 124, 124] references, sum=372
test_os leaked [114, 114, 114] memory blocks, sum=342
test_os failed in 32 sec

1 test failed:
    test_os

Total duration: 32 sec
Tests result: FAILURE
----

Which methods caused the refleak?

Is it possible to list test methods of a test file using unittest?
msg294827 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-05-31 09:26
First step: I created the issue #30523, "unittest: add --list-tests option to only display the list of test names, don't run tests".
msg294962 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-06-01 20:22
I don't understand how issue30523 and issue30540 can help to resolve this issue.
msg294964 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-06-01 20:46
Serhiy: "I don't understand how issue30523 and issue30540 can help to resolve this issue."

- issue30523 produces a list of all test methods
- issue30540 allows to pass a file to filter tests
- attached bisect_test.py takes an input file produced by --list-tests and uses --matchfile to run tests

Example of usage:

./python bisect_test.py test_tools tests bisect -n 5 

* bisect -R 3:3 on test_tools
* tests contains the list of test identifiers to test_tools
* write result into the file "bisect"
* stop bisection when there is 5 tests or less
msg294965 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-06-01 20:47
The next step is to add a command to regrtest implementing all steps. Or maybe this script is enough? At least, it's enough for my needs ;-)
msg295449 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-06-08 15:48
Updated script: support Windows, fix cmdline help.
msg295450 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-06-08 15:53
Oops, I uploaded the wrong version. It should now work.
msg297081 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-06-28 00:24
New changeset 84d9d14a1fa395fbd21262ba195490be25a7b3bc by Victor Stinner in branch 'master':
bpo-29512: Add test.bisect, bisect failing tests (#2452)
https://github.com/python/cpython/commit/84d9d14a1fa395fbd21262ba195490be25a7b3bc
msg297093 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-06-28 00:59
Ok, I pushed a first implementation. It's problaby buggy and incomplete, but it's better than nothing, and can be enhanced later.

I prefer to play with it longer before starting to backport it to other branches, to not have to backport changes multiple times.

Thanks Yury for the review ;-)
msg297421 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-06-30 15:31
New changeset a3ca94d0504157a112a1f89bfe8be1307116fc73 by Victor Stinner in branch '3.6':
[3.6] bpo-29512, bpo-30776: Backport regrtest enhancements from master to 3.6 (#2513)
https://github.com/python/cpython/commit/a3ca94d0504157a112a1f89bfe8be1307116fc73
msg297566 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-07-03 11:17
New changeset 0b1210739d12c26e4a161ffd494bd572d49b2483 by Victor Stinner in branch '3.5':
[3.5] bpo-29512, bpo-30764, bpo-30776: Backport regrtest enhancements from 3.6 to 3.5 (#2540)
https://github.com/python/cpython/commit/0b1210739d12c26e4a161ffd494bd572d49b2483
msg297576 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-07-03 13:07
New changeset d7955b8196578306e9d86f6c61c9cb3ee72edab0 by Victor Stinner in branch '2.7':
[2.7] bpo-29512, bpo-30764: Backport regrtest enhancements from 3.5 to 2.7 (#2541)
https://github.com/python/cpython/commit/d7955b8196578306e9d86f6c61c9cb3ee72edab0
msg297586 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-07-03 13:53
Ok! "python -m test.bisect" is now available in 2.7, 3.5, 3.6 and master branches ;-)
msg299043 - (view) Author: Pierre Quentel (quentel) * Date: 2017-07-25 07:21
Maybe it's me who is doing things wrong, but when I run Lib/test/test_httpservers.py I get this strange error :

Traceback (most recent call last):
  File "C:\cpython\Lib\test\test_httpservers.py", line 7, in <module>
    from http.server import BaseHTTPRequestHandler, HTTPServer, \
  File "c:\python36\lib\http\server.py", line 92, in <module>
    import email.utils
  File "c:\python36\lib\email\utils.py", line 28, in <module>
    import random
  File "c:\python36\lib\random.py", line 48, in <module>
    import bisect as _bisect
  File "C:\cpython\Lib\test\bisect.py", line 27, in <module>
    import tempfile
  File "c:\python36\lib\tempfile.py", line 45, in <module>
    from random import Random as _Random
ImportError: cannot import name 'Random'

I see that the bisect module is loaded from location /test/bisect.py because of the script introduced in the resolution of this issue. Is it intentional to give it the same name as a module of the standard library ?
msg299045 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-07-25 08:16
There are many ways of running tests, and some of them are broken now.

$ ./python Lib/test/test_bisect.py
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
======================================================================
ERROR: test_backcompatibility (__main__.TestBisectC)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Lib/test/test_bisect.py", line 34, in setUp
    (self.module.bisect_right, [], 1, 0),
AttributeError: module 'bisect' has no attribute 'bisect_right'

...
msg299047 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-07-25 09:07
Workarounds:

* ./python -m test test_httpservers
* ./python -I Lib/test/test_httpservers.py

> Maybe it's me who is doing things wrong, but when I run Lib/test/test_httpservers.py I get this strange error :

...
  File "c:\python36\lib\random.py", line 48, in <module>
    import bisect as _bisect
  File "C:\cpython\Lib\test\bisect.py", line 27, in <module>
...

Oh. Lib/test/ should not be in sys.path. "import bisect" loaded Lib/test/bisect.py instead of Lib/bisect.py. See my commit 3050987d85d7cf8cdd4b3c053e673d13cd8dfb12 in Python 2.7:

    * regrtest now removes '' and Lib/test/ from sys.path
    * Use absolute import in test_bisect

(regrtest in master already does something similar.)

But the sys.path is only fixed when regrtest is used...


> There are many ways of running tests, and some of them are broken now.
> $ ./python Lib/test/test_bisect.py

... if you run Lib/test/test_xxx.py directly, Lib/test/ is added to sys.path, except if you use -I:

$ ./python -I Lib/test/test_bisect.py 
....................................
----------------------------------------------------------------------
Ran 36 tests in 0.094s

OK


I didn't know that "./python Lib/test/test_bisect.py" was broken :-(

Maybe Lib/test/support/__init__.py can remove Lib/test/ from sys.path?

Another option is to move or rename Lib/test/bisect.py. For example, replace "./python -m test.bisect ..." with "./python -m test bisect ..." (or maybe "./python -m test --bisect ..."). The problem is that bisect has extra options, but we can add a bisect prefix to these options.

I reopen this issue.
msg306825 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-11-23 16:04
New changeset 448c6739877a4143a2c3599f041fa6127f354044 by Victor Stinner in branch '2.7':
bpo-29512: Fix Lib/test/bisect.py shebang (#4522)
https://github.com/python/cpython/commit/448c6739877a4143a2c3599f041fa6127f354044
msg306876 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-11-24 01:39
Python 2.7.14 was released with test.bisect.

While there are corner cases, do we really have to do something?

The simplest fix is just to rename Lib/test/bisect.py to Lib/test/bisect_cmd.py in Python 2.7. It's a tool written for CPython developer, it's CLI is not stable nor documented.

It just mean replacing "./python -m test.bisect ..." with "./python -m test.bisect_cmd ...", not a big deal.

What do you think of renaming the script?
msg318134 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-05-29 22:45
I created the PR 7229 to rename Lib/test/bisect.py to Lib/test/bisect_cmd.py.
msg318191 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-05-30 15:24
New changeset 823c295efa4efea93cadc640ed6122cd9d86cec4 by Victor Stinner in branch '2.7':
bpo-29512: Rename Lib/test/bisect.py to bisect_cmd.py (#7229)
https://github.com/python/cpython/commit/823c295efa4efea93cadc640ed6122cd9d86cec4
msg318192 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-05-30 15:25
One year later, all issues have now been fixed ;-)
History
Date User Action Args
2019-05-02 02:52:21miss-islingtonsetpull_requests: + pull_request12969
2019-05-02 02:52:02miss-islingtonsetpull_requests: + pull_request12968
2019-05-01 14:40:40xtreaksetpull_requests: + pull_request12959
2018-05-30 15:25:05vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg318192

stage: patch review -> resolved
2018-05-30 15:24:44vstinnersetmessages: + msg318191
2018-05-29 22:45:54vstinnersetmessages: + msg318134
2018-05-29 22:43:38vstinnersetpull_requests: + pull_request6861
2017-11-24 01:39:25vstinnersetmessages: + msg306876
2017-11-23 16:04:37vstinnersetmessages: + msg306825
2017-11-23 15:35:34vstinnersetkeywords: + patch
stage: resolved -> patch review
pull_requests: + pull_request4459
2017-07-25 09:07:26vstinnersetstatus: closed -> open
resolution: fixed -> (no value)
messages: + msg299047
2017-07-25 08:16:25serhiy.storchakasetmessages: + msg299045
2017-07-25 07:21:50quentelsetnosy: + quentel
messages: + msg299043
2017-07-11 08:19:37vstinnerlinkissue22607 superseder
2017-07-03 13:53:28vstinnersetmessages: + msg297586
2017-07-03 13:07:56vstinnersetmessages: + msg297576
2017-07-03 11:30:57vstinnersetpull_requests: + pull_request2609
2017-07-03 11:17:00vstinnersetmessages: + msg297566
2017-07-03 10:57:21vstinnersetpull_requests: + pull_request2606
2017-06-30 15:31:19vstinnersetmessages: + msg297421
2017-06-30 15:11:15vstinnersetpull_requests: + pull_request2582
2017-06-28 00:59:02vstinnersetstatus: open -> closed

nosy: + yselivanov
messages: + msg297093

resolution: fixed
stage: resolved
2017-06-28 00:24:44vstinnersetmessages: + msg297081
2017-06-27 21:51:47vstinnersetpull_requests: + pull_request2509
2017-06-08 15:53:17vstinnersetfiles: + bisect_test.py

messages: + msg295450
2017-06-08 15:48:12vstinnersetfiles: + bisect_test.py

messages: + msg295449
2017-06-01 20:47:40vstinnersetmessages: + msg294965
2017-06-01 20:46:18vstinnersetfiles: + bisect_test.py

messages: + msg294964
2017-06-01 20:22:40serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg294962
2017-05-31 09:26:34vstinnersetmessages: + msg294827
2017-02-09 11:46:03vstinnercreate