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
6c9fc4cf
Kaydet (Commit)
6c9fc4cf
authored
Nis 01, 2010
tarafından
R. David Murray
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
A couple small grammar fixes in test.rst, and rewrite the
check_warnings docs to be clearer.
üst
4fcf7d44
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
38 deletions
+46
-38
test.rst
Doc/library/test.rst
+46
-38
No files found.
Doc/library/test.rst
Dosyayı görüntüle @
6c9fc4cf
...
...
@@ -235,15 +235,15 @@ The :mod:`test.test_support` module defines the following constants:
.. data:: TESTFN
Set to
the name that a temporary file could use. Any temporary file that is
created should be closed and unlinked (removed).
Set to
a name that is safe to use as the name of a temporary file. Any
temporary file that is
created should be closed and unlinked (removed).
The :mod:`test.test_support` module defines the following functions:
.. function:: forget(module_name)
Remove the module named *module_name* from ``sys.modules`` and delete
s
any
Remove the module named *module_name* from ``sys.modules`` and delete any
byte-compiled files of the module.
...
...
@@ -286,49 +286,55 @@ The :mod:`test.test_support` module defines the following functions:
This will run all tests defined in the named module.
.. function:: check_warnings(*filters, quiet=
Non
e)
.. function:: check_warnings(*filters, quiet=
Tru
e)
A convenience wrapper for ``warnings.catch_warnings()`` that makes
it easier to test that a warning was correctly raised with a single
assertion. It is approximately equivalent to calling
``warnings.catch_warnings(record=True)``.
A convenience wrapper for :func:`warnings.catch_warnings()` that makes it
easier to test that a warning was correctly raised. It is approximately
equivalent to calling ``warnings.catch_warnings(record=True)`` with
:meth:`warnings.simplefilter` set to ``always`` and with the option to
automatically validate the results that are recorded.
It accepts 2-tuples ``("message regexp", WarningCategory)`` as positional
arguments. If there'
s
some
``*
filters
``
defined
,
or
if
the
optional
keyword
argument
``
quiet
``
is
:
const
:`
False
`,
it
checks
if
the
warnings
are
effective
.
If
some
filter
did
not
catch
any
warning
,
the
test
fails
.
If
some
warnings
are
not
caught
,
the
test
fails
,
too
.
To
disable
these
checks
,
set
argument
``
quiet
``
to
:
const
:`
True
`.
``check_warnings`` accepts 2-tuples of the form ``("message regexp",
WarningCategory)`` as positional arguments. If one or more *filters* are
provided, or if the optional keyword argument *quiet* is :const:`False`,
it checks to make sure the warnings are as expected: each specified filter
must match at least one of the warnings raised by the enclosed code or the
test fails, and if any warnings are raised that do not match any of the
specified filters the test fails. To disable the first of these checks,
set *quiet* to :const:`True`.
Without
argument
,
it
defaults
to
::
If no arguments are specified
, it defaults to::
check_warnings(("", Warning), quiet=True)
Additionally
,
on
entry
to
the
context
manager
,
a
:
class
:`
WarningRecorder
`
instance
is
returned
.
The
underlying
warnings
list
is
available
via
the
recorder
object
's :attr:`warnings` attribute, while the attributes of the
last raised warning are also accessible directly on the object. If no
warning has been raised, then the latter attributes will all be
:const:`None`.
In this case all warnings are caught and no errors are raised.
A :meth:`reset` method is also provided on the recorder object. This
method simply clears the warnings list.
On entry to the context manager, a :class:`WarningRecorder` instance is
returned. The underlying warnings list from
:func:`~warnings.catch_warnings` is available via the recorder object'
s
:
attr
:`
warnings
`
attribute
.
As
a
convenience
,
the
attributes
of
the
object
representing
the
most
recent
warning
can
also
be
accessed
directly
through
the
recorder
object
(
see
example
below
).
If
no
warning
has
been
raised
,
then
any
of
the
attributes
that
would
otherwise
be
expected
on
an
object
representing
a
warning
will
return
:
const
:`
None
`.
The context manager may be used like this::
The
recorder
object
also
has
a
:
meth
:`
reset
`
method
,
which
clears
the
warnings
list
.
import warnings
with check_warnings(quiet=False):
exec('
assert
(
False
,
"Hey!"
)
')
warnings.warn(UserWarning("Hide me!"))
The
context
manager
is
designed
to
be
used
like
this
::
with
check_warnings
((
"assertion is always true"
,
SyntaxWarning
),
(
""
,
UserWarning
)):
exec
(
'assert(False, "Hey!")'
)
warnings
.
warn
(
UserWarning
(
"Hide me!"
))
In
this
case
if
either
warning
was
not
raised
,
or
some
other
warning
was
raised
,
:
func
:`
check_warnings
`
would
raise
an
error
.
When
a
test
needs
to
look
more
deeply
into
the
warnings
,
rather
than
just
checking
whether
or
not
they
occurred
,
code
like
this
can
be
used
::
with
check_warnings
(
quiet
=
True
)
as
w
:
warnings.simplefilter("always")
warnings
.
warn
(
"foo"
)
assert
str
(
w
.
args
[
0
])
==
"foo"
warnings
.
warn
(
"bar"
)
...
...
@@ -338,21 +344,23 @@ The :mod:`test.test_support` module defines the following functions:
w
.
reset
()
assert
len
(
w
.
warnings
)
==
0
Here
all
warnings
will
be
caught
,
and
the
test
code
tests
the
captured
warnings
directly
.
..
versionadded
::
2.6
..
versionchanged
::
2.7
New optional a
ttributes ``*filters`` and ``quiet``
.
New
optional
a
rguments
*
filters
*
and
*
quiet
*
.
..
function
::
check_py3k_warnings
(*
filters
,
quiet
=
False
)
S
ame as :func:`check_warnings`
but for Python 3 compatibility warnings.
S
imilar
to
:
func
:`
check_warnings
`,
but
for
Python
3
compatibility
warnings
.
If
``
sys
.
py3kwarning
==
1
``,
it
checks
if
the
warning
is
effectively
raised
.
If ``sys.py3kwarning == 0``, it checks that no warning is raised.
It accepts 2-tuples ``("message regexp", WarningCategory)`` as positional
arguments. When the optional keyword argument ``quiet`` is :const:`True`, it
does not fail if a filter catches nothing. Without argument, it defaults
to::
If
``
sys
.
py3kwarning
==
0
``,
it
checks
that
no
warning
is
raised
.
It
accepts
2
-
tuples
of
the
form
``(
"message regexp"
,
WarningCategory
)``
as
positional
arguments
.
When
the
optional
keyword
argument
*
quiet
*
is
:
const
:`
True
`,
it
does
not
fail
if
a
filter
catches
nothing
.
Without
arguments
,
it
defaults
to
::
check_py3k_warnings
((
""
,
DeprecationWarning
),
quiet
=
False
)
...
...
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