Skip to content

Commit 1500159

Browse files
Merge pull request #180 from pytest-dev/fix-py-error
fix up py.error importability
2 parents bb4d0d0 + 0d8b5d4 commit 1500159

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
=====
33

44
- fix #169, #170: error importing py.log on Windows: no module named ``syslog``.
5+
- fix #179: ensure we can support 'from py.error import ...'
56

67
1.5.1
78
=====

py/__init__.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
99
(c) Holger Krekel and others, 2004-2014
1010
"""
11-
__version__ = '1.5.2'
11+
from py._error import error
1212

1313
try:
1414
from py._vendored_packages import apipkg
@@ -18,15 +18,12 @@
1818
import apipkg
1919
lib_not_mangled_by_packagers = False
2020
vendor_prefix = ''
21+
__version__ = '1.5.2'
2122

22-
# so that py.error.* instances are picklable
23-
import sys
2423

25-
apipkg.initpkg(__name__, attr={'_apipkg': apipkg}, exportdefs={
24+
apipkg.initpkg(__name__, attr={'_apipkg': apipkg, 'error': error}, exportdefs={
2625
# access to all standard lib modules
2726
'std': '._std:std',
28-
# access to all posix errno's as classes
29-
'error': '._error:error',
3027

3128
'_pydir' : '.__metainfo:pydir',
3229
'version': 'py:__version__', # backward compatibility

testing/root/test_error.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import py
33

44
import errno
5+
import sys
6+
import subprocess
57

68

79
def test_error_classes():
@@ -33,7 +35,7 @@ def test_unknown_error():
3335
assert cls is cls2
3436

3537

36-
def test_error_conversion_ENOTDIR(testdir):
38+
def test_error_conversion_enotdir(testdir):
3739
p = testdir.makepyfile("")
3840
excinfo = py.test.raises(py.error.Error, py.error.checked_call, p.listdir)
3941
assert isinstance(excinfo.value, EnvironmentError)
@@ -46,6 +48,12 @@ def test_checked_call_supports_kwargs(tmpdir):
4648
py.error.checked_call(tempfile.mkdtemp, dir=str(tmpdir))
4749

4850

51+
def test_error_importable():
52+
"""Regression test for #179"""
53+
subprocess.check_call(
54+
[sys.executable, '-c', 'from py.error import ENOENT'])
55+
56+
4957
try:
5058
import unittest
5159
unittest.TestCase.assertWarns
@@ -56,13 +64,13 @@ def test_checked_call_supports_kwargs(tmpdir):
5664
import warnings
5765

5866
class Case(unittest.TestCase):
59-
def test_assertWarns(self):
67+
def test_assert_warns(self):
6068
# Clear everything "py.*" from sys.modules and re-import py
6169
# as a fresh start
6270
for mod in tuple(sys.modules.keys()):
6371
if mod and (mod == 'py' or mod.startswith('py.')):
6472
del sys.modules[mod]
65-
import py
73+
__import__('py')
6674

6775
with self.assertWarns(UserWarning):
6876
warnings.warn('this should work')

tox.ini

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ envlist=py{27,34,35,36}-pytest{29,30,31}
44
[testenv]
55
changedir=testing
66
commands=
7-
pip install -U .. # hande the install order fallout since pytest depends on pip
8-
9-
py.test --confcutdir=.. -rfsxX --junitxml={envlogdir}/junit-{envname}.xml []
7+
pip install -U .. # hande the install order fallout since pytest depends on pip
8+
py.test --confcutdir=.. -rfsxX --junitxml={envlogdir}/junit-{envname}.xml []
109
deps=
11-
pytest29: pytest~=2.9.0
12-
pytest30: pytest~=3.0.0
13-
pytest31: pytest~=3.1.0
10+
attrs
11+
pytest29: pytest~=2.9.0
12+
pytest30: pytest~=3.0.0
13+
pytest31: pytest~=3.1.0
1414

1515
[testenv:py27-xdist]
1616
basepython=python2.7

0 commit comments

Comments
 (0)