Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
42ec7cb1
Kaydet (Commit)
42ec7cb1
authored
Mar 17, 2011
tarafından
Michael Foord
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #10979. unittest stdout buffering now works with class and module setup and teardown.
üst
b2760a0b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
94 additions
and
2 deletions
+94
-2
result.py
Lib/unittest/result.py
+7
-1
suite.py
Lib/unittest/suite.py
+17
-1
test_result.py
Lib/unittest/test/test_result.py
+67
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/unittest/result.py
Dosyayı görüntüle @
42ec7cb1
...
...
@@ -59,6 +59,9 @@ class TestResult(object):
"Called when the given test is about to be run"
self
.
testsRun
+=
1
self
.
_mirrorOutput
=
False
self
.
_setupStdout
()
def
_setupStdout
(
self
):
if
self
.
buffer
:
if
self
.
_stderr_buffer
is
None
:
self
.
_stderr_buffer
=
io
.
StringIO
()
...
...
@@ -74,6 +77,10 @@ class TestResult(object):
def
stopTest
(
self
,
test
):
"""Called when the given test has been run"""
self
.
_restoreStdout
()
self
.
_mirrorOutput
=
False
def
_restoreStdout
(
self
):
if
self
.
buffer
:
if
self
.
_mirrorOutput
:
output
=
sys
.
stdout
.
getvalue
()
...
...
@@ -93,7 +100,6 @@ class TestResult(object):
self
.
_stdout_buffer
.
truncate
()
self
.
_stderr_buffer
.
seek
(
0
)
self
.
_stderr_buffer
.
truncate
()
self
.
_mirrorOutput
=
False
def
stopTestRun
(
self
):
"""Called once after all tests are executed.
...
...
Lib/unittest/suite.py
Dosyayı görüntüle @
42ec7cb1
...
...
@@ -8,6 +8,11 @@ from . import util
__unittest
=
True
def
_call_if_exists
(
parent
,
attr
):
func
=
getattr
(
parent
,
attr
,
lambda
:
None
)
func
()
class
BaseTestSuite
(
object
):
"""A simple test suite that doesn't provide class or module shared fixtures.
"""
...
...
@@ -133,6 +138,7 @@ class TestSuite(BaseTestSuite):
setUpClass
=
getattr
(
currentClass
,
'setUpClass'
,
None
)
if
setUpClass
is
not
None
:
_call_if_exists
(
result
,
'_setupStdout'
)
try
:
setUpClass
()
except
Exception
as
e
:
...
...
@@ -142,6 +148,8 @@ class TestSuite(BaseTestSuite):
className
=
util
.
strclass
(
currentClass
)
errorName
=
'setUpClass (
%
s)'
%
className
self
.
_addClassOrModuleLevelException
(
result
,
e
,
errorName
)
finally
:
_call_if_exists
(
result
,
'_restoreStdout'
)
def
_get_previous_module
(
self
,
result
):
previousModule
=
None
...
...
@@ -167,6 +175,7 @@ class TestSuite(BaseTestSuite):
return
setUpModule
=
getattr
(
module
,
'setUpModule'
,
None
)
if
setUpModule
is
not
None
:
_call_if_exists
(
result
,
'_setupStdout'
)
try
:
setUpModule
()
except
Exception
as
e
:
...
...
@@ -175,6 +184,8 @@ class TestSuite(BaseTestSuite):
result
.
_moduleSetUpFailed
=
True
errorName
=
'setUpModule (
%
s)'
%
currentModule
self
.
_addClassOrModuleLevelException
(
result
,
e
,
errorName
)
finally
:
_call_if_exists
(
result
,
'_restoreStdout'
)
def
_addClassOrModuleLevelException
(
self
,
result
,
exception
,
errorName
):
error
=
_ErrorHolder
(
errorName
)
...
...
@@ -198,6 +209,7 @@ class TestSuite(BaseTestSuite):
tearDownModule
=
getattr
(
module
,
'tearDownModule'
,
None
)
if
tearDownModule
is
not
None
:
_call_if_exists
(
result
,
'_setupStdout'
)
try
:
tearDownModule
()
except
Exception
as
e
:
...
...
@@ -205,6 +217,8 @@ class TestSuite(BaseTestSuite):
raise
errorName
=
'tearDownModule (
%
s)'
%
previousModule
self
.
_addClassOrModuleLevelException
(
result
,
e
,
errorName
)
finally
:
_call_if_exists
(
result
,
'_restoreStdout'
)
def
_tearDownPreviousClass
(
self
,
test
,
result
):
previousClass
=
getattr
(
result
,
'_previousTestClass'
,
None
)
...
...
@@ -220,6 +234,7 @@ class TestSuite(BaseTestSuite):
tearDownClass
=
getattr
(
previousClass
,
'tearDownClass'
,
None
)
if
tearDownClass
is
not
None
:
_call_if_exists
(
result
,
'_setupStdout'
)
try
:
tearDownClass
()
except
Exception
as
e
:
...
...
@@ -228,7 +243,8 @@ class TestSuite(BaseTestSuite):
className
=
util
.
strclass
(
previousClass
)
errorName
=
'tearDownClass (
%
s)'
%
className
self
.
_addClassOrModuleLevelException
(
result
,
e
,
errorName
)
finally
:
_call_if_exists
(
result
,
'_restoreStdout'
)
class
_ErrorHolder
(
object
):
...
...
Lib/unittest/test/test_result.py
Dosyayı görüntüle @
42ec7cb1
...
...
@@ -497,5 +497,72 @@ class TestOutputBuffering(unittest.TestCase):
self
.
assertEqual
(
result
.
_original_stderr
.
getvalue
(),
expectedErrMessage
)
self
.
assertMultiLineEqual
(
message
,
expectedFullMessage
)
def
testBufferSetupClass
(
self
):
result
=
unittest
.
TestResult
()
result
.
buffer
=
True
class
Foo
(
unittest
.
TestCase
):
@classmethod
def
setUpClass
(
cls
):
1
/
0
def
test_foo
(
self
):
pass
suite
=
unittest
.
TestSuite
([
Foo
(
'test_foo'
)])
suite
(
result
)
self
.
assertEqual
(
len
(
result
.
errors
),
1
)
def
testBufferTearDownClass
(
self
):
result
=
unittest
.
TestResult
()
result
.
buffer
=
True
class
Foo
(
unittest
.
TestCase
):
@classmethod
def
tearDownClass
(
cls
):
1
/
0
def
test_foo
(
self
):
pass
suite
=
unittest
.
TestSuite
([
Foo
(
'test_foo'
)])
suite
(
result
)
self
.
assertEqual
(
len
(
result
.
errors
),
1
)
def
testBufferSetUpModule
(
self
):
result
=
unittest
.
TestResult
()
result
.
buffer
=
True
class
Foo
(
unittest
.
TestCase
):
def
test_foo
(
self
):
pass
class
Module
(
object
):
@staticmethod
def
setUpModule
():
1
/
0
Foo
.
__module__
=
'Module'
sys
.
modules
[
'Module'
]
=
Module
self
.
addCleanup
(
sys
.
modules
.
pop
,
'Module'
)
suite
=
unittest
.
TestSuite
([
Foo
(
'test_foo'
)])
suite
(
result
)
self
.
assertEqual
(
len
(
result
.
errors
),
1
)
def
testBufferTearDownModule
(
self
):
result
=
unittest
.
TestResult
()
result
.
buffer
=
True
class
Foo
(
unittest
.
TestCase
):
def
test_foo
(
self
):
pass
class
Module
(
object
):
@staticmethod
def
tearDownModule
():
1
/
0
Foo
.
__module__
=
'Module'
sys
.
modules
[
'Module'
]
=
Module
self
.
addCleanup
(
sys
.
modules
.
pop
,
'Module'
)
suite
=
unittest
.
TestSuite
([
Foo
(
'test_foo'
)])
suite
(
result
)
self
.
assertEqual
(
len
(
result
.
errors
),
1
)
if
__name__
==
'__main__'
:
unittest
.
main
()
Misc/NEWS
Dosyayı görüntüle @
42ec7cb1
...
...
@@ -10,6 +10,9 @@ What's New in Python 3.2.1?
Core and Builtins
-----------------
- Issue #10979: unittest stdout buffering now works with class and module
setup and teardown.
- Issue #11510: Fixed optimizer bug which turned "a,b={1,1}" into "a,b=(1,1)".
- Issue #11432: A bug was introduced in subprocess.Popen on posix systems with
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment