Skip to content

Commit

Permalink
Attempt to fix win32 test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Erotemic committed Sep 2, 2021
1 parent d85d12b commit 02e99a1
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 27 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
* Removed the distracting and very long internal traceback that occurred in
pytest when a module errors while it is being imported before the doctest is
run.
* Pytest now defaults to `--xdoctest-verbose=2` by default (note this does
nothing unless `-s` is also given so pytest does not supress output)


### Fixed
Expand Down
19 changes: 10 additions & 9 deletions testing/test_pytest_errors.py → testing/test_pytest_cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from xdoctest.utils import util_misc
import sys
from xdoctest import utils


Expand Down Expand Up @@ -34,7 +35,7 @@ def module_func1():
temp_module = util_misc.TempModule(module_text)
modpath = temp_module.modpath

info = cmd('pytest --xdoctest ' + modpath)
info = cmd(sys.executable + ' -m pytest --xdoctest ' + modpath)
print(info['out'])
assert info['ret'] == 0

Expand All @@ -44,11 +45,11 @@ def test_simple_pytest_import_error_cli():
This test case triggers an excessively long callback in xdoctest <
dev/0.15.7
xdoctest ~/code/xdoctest/testing/test_pytest_errors.py test_simple_pytest_import_error_cli
xdoctest ~/code/xdoctest/testing/test_pytest_cli.py test_simple_pytest_import_error_cli
import sys, ubelt
sys.path.append(ubelt.expandpath('~/code/xdoctest/testing'))
from test_pytest_errors import * # NOQA
from test_pytest_cli import * # NOQA
"""
module_text = utils.codeblock(
'''
Expand All @@ -66,7 +67,7 @@ def module_func1():
"""
''')
temp_module = util_misc.TempModule(module_text, modname='imperr_test_mod')
command = 'pytest -v -s --xdoctest-verbose=3 --xdoctest ' + temp_module.dpath
command = sys.executable + ' -m pytest -v -s --xdoctest-verbose=3 --xdoctest ' + temp_module.dpath
print(command)
info = cmd(command)
print(info['out'])
Expand All @@ -93,10 +94,10 @@ def module_func1():
"""
''')
temp_module = util_misc.TempModule(module_text)
info = cmd('pytest --xdoctest ' + temp_module.dpath)
info = cmd(sys.executable + ' -m pytest --xdoctest ' + temp_module.dpath)
print(info['out'])

info = cmd('pytest --xdoctest ' + temp_module.modpath)
info = cmd(sys.executable + ' -m pytest --xdoctest ' + temp_module.modpath)
print(info['out'])


Expand All @@ -111,7 +112,7 @@ def test_this():
print('hello world')
''')
temp_module = util_misc.TempModule(module_text)
info = cmd('pytest ' + temp_module.modpath)
info = cmd(sys.executable + ' -m pytest ' + temp_module.modpath)
print(info['out'])

info = cmd('pytest ' + temp_module.dpath)
Expand All @@ -130,9 +131,9 @@ def test_this():
print('hello world')
''')
temp_module = util_misc.TempModule(module_text)
info = cmd('pytest ' + temp_module.modpath)
info = cmd(sys.executable + ' -m pytest ' + temp_module.modpath)
print(info['out'])

info = cmd('pytest ' + temp_module.dpath)
info = cmd(sys.executable + ' -m pytest ' + temp_module.dpath)
print(info['out'])
# assert info['ret'] == 0
2 changes: 1 addition & 1 deletion xdoctest/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class RawDescriptionDefaultsHelpFormatter(
Defaults --modname to arg.pop(0).
Defaults --command to arg.pop(0).
'''))
parser.add_argument('--version', action='store_true', help='display version info and quit')
parser.add_argument('--version', action='store_true', help='Display version info and quit')

# The bulk of the argparse CLI is defined in the doctest example
from xdoctest import doctest_example
Expand Down
21 changes: 13 additions & 8 deletions xdoctest/doctest_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,27 @@ def str_lower(x):
help=('Disable ANSI coloration in stdout'))),
(['--offset'], dict(dest='offset_linenos', action='store_true',
default=self['offset_linenos'],
help=('if True formatted source linenumbers will agree with '
help=('If True formatted source linenumbers will agree with '
'their location in the source file. Otherwise they '
'will be relative to the doctest itself.'))),
(['--report'], dict(dest='reportchoice',
type=str_lower,
choices=('none', 'cdiff', 'ndiff', 'udiff', 'only_first_failure',),
default=self['reportchoice'],
help=('choose another output format for diffs on xdoctest failure'))),
help=('Choose another output format for diffs on xdoctest failure'))),
# used to build default_runtime_state
(['--options'], dict(type=str_lower, default=None, dest='options',
help='default directive flags for doctests')),
help='Default directive flags for doctests')),
(['--global-exec'], dict(type=str, default=None, dest='global_exec',
help='exec these lines before every test')),
(['--verbose'], dict(type=int, default=defaults.get('verbose', 3), dest='verbose',
help='verbosity level')),
# (['--verbose'], dict(action='store_true', dest='verbose')),
help='Custom Python code to execute before every test')),
(['--verbose'], dict(
type=int, default=defaults.get('verbose', 3), dest='verbose',
help=(
'Verbosity level. '
'0 is silent, '
'1 prints out test names, '
'2 additionally prints test stdout, '
'3 additionally prints test source'))),
(['--quiet'], dict(action='store_true', dest='verbose',
default=argparse.SUPPRESS,
help='sets verbosity to 1')),
Expand Down Expand Up @@ -303,7 +308,7 @@ def is_disabled(self, pytest=False):
@property
def unique_callname(self):
"""
A key that references this doctest within xdoctest given its module
A key that references this doctest given its module
"""
return self.callname + ':' + str(self.num)

Expand Down
12 changes: 7 additions & 5 deletions xdoctest/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,25 @@ def str_lower(x):
# type="args", default=["+ELLIPSIS"])
group.addoption('--xdoctest-modules', '--xdoctest', '--xdoc',
action='store_true', default=False,
help='run doctests in all .py modules using new style parsing',
help='Run doctests in all .py modules using new style parsing',
dest='xdoctestmodules')
group.addoption('--xdoctest-glob', '--xdoc-glob',
action='append', default=[], metavar='pat',
help=(
'text files matching this pattern will be checked '
'Text files matching this pattern will be checked '
'for doctests. This option may be specified multiple '
'times. XDoctest does not check any text files by '
'default. For compatibility with doctest set this to '
'test*.txt'),
dest='xdoctestglob')
group.addoption('--xdoctest-ignore-syntax-errors',
action='store_true', default=False,
help='ignore xdoctest SyntaxErrors',
help='Ignore xdoctest SyntaxErrors',
dest='xdoctest_ignore_syntax_errors')

group.addoption('--xdoctest-style', '--xdoc-style',
type=str_lower, default='freeform',
help='basic style used to write doctests',
help='Basic style used to write doctests',
choices=core.DOCTEST_STYLES,
dest='xdoctest_style')

Expand All @@ -107,7 +107,7 @@ def str_lower(x):
from xdoctest import doctest_example
doctest_example.DoctestConfig()._update_argparse_cli(
group.addoption, prefix=['xdoctest', 'xdoc'],
defaults=dict(verbose=0)
defaults=dict(verbose=2)
)


Expand Down Expand Up @@ -207,7 +207,9 @@ def __getattr__(self, attr):
ns = NamespaceLike(self.config)

from xdoctest import doctest_example
print('ns = {!r}'.format(ns.__dict__['config'].__dict__))
self._examp_conf = doctest_example.DoctestConfig()._populate_from_cli(ns)
print('self._examp_conf = {!r}'.format(self._examp_conf))


class XDoctestTextfile(_XDoctestBase):
Expand Down
8 changes: 4 additions & 4 deletions xdoctest/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,24 +571,24 @@ def str_lower(x):
return str.lower(str(x))

add_argument(*('-m', '--modname'), type=str,
help='module name or path. If specified positional modules are ignored',
help='Module name or path. If specified positional modules are ignored',
default=None)

add_argument(*('-c', '--command'), type=str,
help='a doctest name or a command (list|all|<callname>). '
help='A doctest name or a command (list|all|<callname>). '
'Defaults to all',
default=None)

add_argument(*('--style',), type=str,
help='choose the style of doctests that will be parsed',
help='Choose the style of doctests that will be parsed',
choices=['auto', 'google', 'freeform'], default='auto')

add_argument(*('--analysis',), type=str,
help='How doctests are collected',
choices=['auto', 'static', 'dynamic'], default='static')

add_argument(*('--durations',), type=int,
help=('specify execution times for slowest N tests.'
help=('Specify execution times for slowest N tests.'
'N=0 will show times for all tests'),
default=None)

Expand Down

0 comments on commit 02e99a1

Please sign in to comment.