Skip to content

Commit b94cb38

Browse files
authored
Merge pull request pytest-dev#171 from nicoddemus/fix-syslog
Fix py.log import error on Windows due to syslog
2 parents 0c7c0e5 + 84888f7 commit b94cb38

File tree

5 files changed

+20
-15
lines changed

5 files changed

+20
-15
lines changed

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
1.5.2
2+
=====
3+
4+
- fix #169, #170: error importing py.log on Windows: no module named ``syslog``.
5+
16
1.5.1
27
=====
38

py/__init__.py

Lines changed: 1 addition & 1 deletion
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.1'
11+
__version__ = '1.5.2'
1212

1313
try:
1414
from py._vendored_packages import apipkg

py/_log/log.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"""
1717
import py
1818
import sys
19-
import syslog
2019

2120

2221
class Message(object):
@@ -190,11 +189,18 @@ def __init__(self, priority=None):
190189

191190
def __call__(self, msg):
192191
""" write a message to the log """
192+
import syslog
193193
syslog.syslog(self.priority, str(msg))
194194

195-
for _prio in "EMERG ALERT CRIT ERR WARNING NOTICE INFO DEBUG".split():
196-
_prio = "LOG_" + _prio
197-
try:
198-
setattr(Syslog, _prio, getattr(syslog, _prio))
199-
except AttributeError:
200-
pass
195+
196+
try:
197+
import syslog
198+
except ImportError:
199+
pass
200+
else:
201+
for _prio in "EMERG ALERT CRIT ERR WARNING NOTICE INFO DEBUG".split():
202+
_prio = "LOG_" + _prio
203+
try:
204+
setattr(Syslog, _prio, getattr(syslog, _prio))
205+
except AttributeError:
206+
pass

testing/log/test_log.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import py
2-
import sys
32

4-
import pytest
3+
from py._log.log import default_keywordmapper
54

65
callcapture = py.io.StdCapture.call
76

8-
default_keywordmapper = pytest.importorskip('py._log.log.default_keywordmapper')
97

108
def setup_module(mod):
119
mod._oldstate = default_keywordmapper.getstate()

testing/root/test_py_imports.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
@py.test.mark.parametrize('name', [x for x in dir(py) if x[0] != '_'])
66
def test_dir(name):
7-
if name == 'log' and sys.platform.startswith('win'):
8-
py.test.skip('syslog is not available on Windows')
97
obj = getattr(py, name)
108
if hasattr(obj, '__map__'): # isinstance(obj, Module):
119
keys = dir(obj)
@@ -54,8 +52,6 @@ def recurse(p):
5452

5553

5654
def check_import(modpath):
57-
if modpath == 'py._log.log' and sys.platform.startswith('win'):
58-
py.test.skip('syslog is not available on Windows')
5955
py.builtin.print_("checking import", modpath)
6056
assert __import__(modpath)
6157

0 commit comments

Comments
 (0)