Added a console option to specify the encoding to use for doctest files. Defaults to UTF-8.
This commit is contained in:
parent
36eb5b36d1
commit
ed977513ec
|
@ -43,6 +43,10 @@ def pytest_addoption(parser):
|
|||
action="store_true", default=False,
|
||||
help="ignore doctest ImportErrors",
|
||||
dest="doctest_ignore_import_errors")
|
||||
group.addoption("--doctest-encoding",
|
||||
type=str.lower, default="utf-8",
|
||||
help="choose the encoding to use for doctest files",
|
||||
dest="doctestencoding")
|
||||
|
||||
|
||||
def pytest_collect_file(path, parent):
|
||||
|
@ -171,7 +175,7 @@ class DoctestTextfile(pytest.Module):
|
|||
|
||||
# inspired by doctest.testfile; ideally we would use it directly,
|
||||
# but it doesn't support passing a custom checker
|
||||
text = self.fspath.read()
|
||||
text = self.fspath.read_text(self.config.getoption("doctestencoding"))
|
||||
filename = str(self.fspath)
|
||||
name = self.fspath.basename
|
||||
globs = {'__name__': '__main__'}
|
||||
|
|
|
@ -11,6 +11,13 @@ can change the pattern by issuing::
|
|||
on the command line. Since version ``2.9``, ``--doctest-glob``
|
||||
can be given multiple times in the command-line.
|
||||
|
||||
You can specify the encoding that will be used for those doctest files
|
||||
using the ``--doctest-encoding`` command line option::
|
||||
|
||||
pytest --doctest-encoding='ascii'
|
||||
|
||||
The default encoding is UTF-8.
|
||||
|
||||
You can also trigger running of doctests
|
||||
from docstrings in all python modules (including regular
|
||||
python test modules)::
|
||||
|
@ -52,9 +59,9 @@ then you can just invoke ``pytest`` without command line options::
|
|||
platform linux -- Python 3.5.2, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
|
||||
rootdir: $REGENDOC_TMPDIR, inifile: pytest.ini
|
||||
collected 1 items
|
||||
|
||||
|
||||
mymodule.py .
|
||||
|
||||
|
||||
======= 1 passed in 0.12 seconds ========
|
||||
|
||||
It is possible to use fixtures using the ``getfixture`` helper::
|
||||
|
|
Loading…
Reference in New Issue