-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from Erotemic/dev/1.0.2
Defer pre-imports until a non-skipped line is about to
- Loading branch information
Showing
4 changed files
with
85 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# -*- coding: utf-8 -*- | ||
from os.path import join | ||
from xdoctest import utils | ||
|
||
|
||
def test_preimport_skiped_on_disabled_module(): | ||
""" | ||
If our module has no enabled tests, pre-import should never run. | ||
""" | ||
|
||
from xdoctest import runner | ||
import os | ||
|
||
source = utils.codeblock( | ||
''' | ||
raise Exception("DONT IMPORT ME!") | ||
def ima_function(): | ||
""" | ||
Example: | ||
>>> # xdoctest: +REQUIRES(env:XDOCTEST_TEST_DOITANYWAY) | ||
>>> print('hello') | ||
""" | ||
''') | ||
|
||
with utils.TempDir() as temp: | ||
dpath = temp.dpath | ||
modpath = join(dpath, 'test_bad_preimport.py') | ||
with open(modpath, 'w') as file: | ||
file.write(source) | ||
os.environ['XDOCTEST_TEST_DOITANYWAY'] = '' | ||
with utils.CaptureStdout() as cap: | ||
runner.doctest_module(modpath, 'all', argv=['']) | ||
assert 'Failed to import modname' not in cap.text | ||
assert '1 skipped' in cap.text | ||
|
||
os.environ['XDOCTEST_TEST_DOITANYWAY'] = '1' | ||
with utils.CaptureStdout() as cap: | ||
runner.doctest_module(modpath, 'all', argv=[]) | ||
assert 'Failed to import modname' in cap.text | ||
|
||
del os.environ['XDOCTEST_TEST_DOITANYWAY'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters