classification
Title: Executing some tests inside Lib/unittest/test individually throws Error
Type: behavior Stage: resolved
Components: Tests Versions: Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ezio.melotti Nosy List: ezio.melotti, michael.foord, python-dev, terry.reedy, vajrasky
Priority: normal Keywords: patch

Created on 2014-07-27 14:50 by vajrasky, last changed 2014-08-07 00:31 by ezio.melotti. This issue is now closed.

Files
File name Uploaded Description Edit
fix_test_inside_unittest.patch vajrasky, 2014-07-27 15:00 review
fix_test_inside_unittest_v2.patch vajrasky, 2014-08-03 15:26 review
Messages (6)
msg224136 - (view) Author: Vajrasky Kok (vajrasky) * Date: 2014-07-27 14:50
For examples:

$ ./python Lib/unittest/test/test_runner.py 
Traceback (most recent call last):
  File "Lib/unittest/test/test_runner.py", line 10, in <module>
    from .support import LoggingResult, ResultWithNoStartTestRunStopTestRun
SystemError: Parent module '' not loaded, cannot perform relative import

$ ./python Lib/unittest/test/test_program.py 
..................E
======================================================================
ERROR: test_discovery_from_dotted_path (__main__.Test_TestProgram)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Lib/unittest/test/test_program.py", line 15, in test_discovery_from_dotted_path
    expectedPath = os.path.abspath(os.path.dirname(unittest.test.__file__))
AttributeError: module 'unittest' has no attribute 'test'

----------------------------------------------------------------------
Ran 19 tests in 0.331s

FAILED (errors=1)


Here is the patch.
msg224637 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2014-08-03 13:38
I left a comment on rietveld.

Michael, do you think changing the imports is OK, or will this cause you some troubles with the external unittest package you maintain?
msg224643 - (view) Author: Vajrasky Kok (vajrasky) * Date: 2014-08-03 15:26
Here is the patch based on Ezio's review. Thanks!
msg224661 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2014-08-03 20:56
Patch looks fine, easy enough to change for unittest2 (if I ever have the time for a new release!)
msg224978 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-08-07 00:29
New changeset 668f6938fb1c by Ezio Melotti in branch '3.4':
#22092: use absolute imports in unittest tests.  Patch by Vajrasky Kok.
http://hg.python.org/cpython/rev/668f6938fb1c

New changeset 09f56fdcacf1 by Ezio Melotti in branch 'default':
#22092: merge with 3.4.
http://hg.python.org/cpython/rev/09f56fdcacf1

New changeset 6e5a2ac30c7e by Ezio Melotti in branch '2.7':
#22092: use absolute imports in unittest tests.  Patch by Vajrasky Kok.
http://hg.python.org/cpython/rev/6e5a2ac30c7e
msg224979 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2014-08-07 00:31
Fixed, thanks for the report and the patch!
History
Date User Action Args
2014-08-07 00:31:49ezio.melottisetstatus: open -> closed
versions: + Python 2.7
messages: + msg224979

assignee: michael.foord -> ezio.melotti
resolution: fixed
stage: patch review -> resolved
2014-08-07 00:29:56python-devsetnosy: + python-dev
messages: + msg224978
2014-08-03 20:56:15michael.foordsetmessages: + msg224661
2014-08-03 15:26:37vajraskysetfiles: + fix_test_inside_unittest_v2.patch

messages: + msg224643
2014-08-03 13:38:41ezio.melottisetassignee: michael.foord
type: behavior
messages: + msg224637
stage: patch review
2014-08-01 22:51:22terry.reedysetnosy: + terry.reedy
2014-07-28 05:37:34serhiy.storchakasetnosy: + ezio.melotti, michael.foord
2014-07-27 15:00:10vajraskysetfiles: + fix_test_inside_unittest.patch
2014-07-27 15:00:02vajraskysetfiles: - fix_test_inside_unittest.patch
2014-07-27 14:50:45vajraskycreate