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
4ab46953
Unverified
Kaydet (Commit)
4ab46953
authored
Haz 10, 2018
tarafından
Tal Einat
Kaydeden (comit)
GitHub
Haz 10, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-33748: fix tests altering sys.path and sys.modules (GH-7433)
üst
1b85c71a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
19 deletions
+20
-19
test_discovery.py
Lib/unittest/test/test_discovery.py
+20
-19
No files found.
Lib/unittest/test/test_discovery.py
Dosyayı görüntüle @
4ab46953
...
@@ -4,10 +4,11 @@ import re
...
@@ -4,10 +4,11 @@ import re
import
sys
import
sys
import
types
import
types
import
pickle
import
pickle
import
builtins
from
test
import
support
from
test
import
support
import
test.test_importlib.util
import
unittest
import
unittest
import
unittest.mock
import
unittest.test
import
unittest.test
...
@@ -820,7 +821,6 @@ class TestDiscovery(unittest.TestCase):
...
@@ -820,7 +821,6 @@ class TestDiscovery(unittest.TestCase):
def
test_discovery_from_dotted_namespace_packages
(
self
):
def
test_discovery_from_dotted_namespace_packages
(
self
):
loader
=
unittest
.
TestLoader
()
loader
=
unittest
.
TestLoader
()
orig_import
=
__import__
package
=
types
.
ModuleType
(
'package'
)
package
=
types
.
ModuleType
(
'package'
)
package
.
__path__
=
[
'/a'
,
'/b'
]
package
.
__path__
=
[
'/a'
,
'/b'
]
package
.
__spec__
=
types
.
SimpleNamespace
(
package
.
__spec__
=
types
.
SimpleNamespace
(
...
@@ -832,11 +832,6 @@ class TestDiscovery(unittest.TestCase):
...
@@ -832,11 +832,6 @@ class TestDiscovery(unittest.TestCase):
sys
.
modules
[
packagename
]
=
package
sys
.
modules
[
packagename
]
=
package
return
package
return
package
def
cleanup
():
builtins
.
__import__
=
orig_import
self
.
addCleanup
(
cleanup
)
builtins
.
__import__
=
_import
_find_tests_args
=
[]
_find_tests_args
=
[]
def
_find_tests
(
start_dir
,
pattern
,
namespace
=
None
):
def
_find_tests
(
start_dir
,
pattern
,
namespace
=
None
):
_find_tests_args
.
append
((
start_dir
,
pattern
))
_find_tests_args
.
append
((
start_dir
,
pattern
))
...
@@ -844,28 +839,34 @@ class TestDiscovery(unittest.TestCase):
...
@@ -844,28 +839,34 @@ class TestDiscovery(unittest.TestCase):
loader
.
_find_tests
=
_find_tests
loader
.
_find_tests
=
_find_tests
loader
.
suiteClass
=
list
loader
.
suiteClass
=
list
suite
=
loader
.
discover
(
'package'
)
with
unittest
.
mock
.
patch
(
'builtins.__import__'
,
_import
):
# Since loader.discover() can modify sys.path, restore it when done.
with
support
.
DirsOnSysPath
():
# Make sure to remove 'package' from sys.modules when done.
with
test
.
test_importlib
.
util
.
uncache
(
'package'
):
suite
=
loader
.
discover
(
'package'
)
self
.
assertEqual
(
suite
,
[
'/a/tests'
,
'/b/tests'
])
self
.
assertEqual
(
suite
,
[
'/a/tests'
,
'/b/tests'
])
def
test_discovery_failed_discovery
(
self
):
def
test_discovery_failed_discovery
(
self
):
loader
=
unittest
.
TestLoader
()
loader
=
unittest
.
TestLoader
()
package
=
types
.
ModuleType
(
'package'
)
package
=
types
.
ModuleType
(
'package'
)
orig_import
=
__import__
def
_import
(
packagename
,
*
args
,
**
kwargs
):
def
_import
(
packagename
,
*
args
,
**
kwargs
):
sys
.
modules
[
packagename
]
=
package
sys
.
modules
[
packagename
]
=
package
return
package
return
package
def
cleanup
(
):
with
unittest
.
mock
.
patch
(
'builtins.__import__'
,
_import
):
builtins
.
__import__
=
orig_import
# Since loader.discover() can modify sys.path, restore it when done.
self
.
addCleanup
(
cleanup
)
with
support
.
DirsOnSysPath
():
builtins
.
__import__
=
_import
# Make sure to remove 'package' from sys.modules when done.
with
test
.
test_importlib
.
util
.
uncache
(
'package'
):
with
self
.
assertRaises
(
TypeError
)
as
cm
:
with
self
.
assertRaises
(
TypeError
)
as
cm
:
loader
.
discover
(
'package'
)
loader
.
discover
(
'package'
)
self
.
assertEqual
(
str
(
cm
.
exception
),
self
.
assertEqual
(
str
(
cm
.
exception
),
'don
\'
t know how to discover from {!r}'
'don
\'
t know how to discover from {!r}'
.
format
(
package
))
.
format
(
package
))
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
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