Skip to content

Commit

Permalink
Merge pull request pytest-dev#171 from nicoddemus/fix-syslog
Browse files Browse the repository at this point in the history
Fix py.log import error on Windows due to syslog
  • Loading branch information
nicoddemus authored Nov 15, 2017
2 parents 0c7c0e5 + 84888f7 commit b94cb38
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
1.5.2
=====

- fix #169, #170: error importing py.log on Windows: no module named ``syslog``.

1.5.1
=====

Expand Down
2 changes: 1 addition & 1 deletion py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
(c) Holger Krekel and others, 2004-2014
"""
__version__ = '1.5.1'
__version__ = '1.5.2'

try:
from py._vendored_packages import apipkg
Expand Down
20 changes: 13 additions & 7 deletions py/_log/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"""
import py
import sys
import syslog


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

def __call__(self, msg):
""" write a message to the log """
import syslog
syslog.syslog(self.priority, str(msg))

for _prio in "EMERG ALERT CRIT ERR WARNING NOTICE INFO DEBUG".split():
_prio = "LOG_" + _prio
try:
setattr(Syslog, _prio, getattr(syslog, _prio))
except AttributeError:
pass

try:
import syslog
except ImportError:
pass
else:
for _prio in "EMERG ALERT CRIT ERR WARNING NOTICE INFO DEBUG".split():
_prio = "LOG_" + _prio
try:
setattr(Syslog, _prio, getattr(syslog, _prio))
except AttributeError:
pass
4 changes: 1 addition & 3 deletions testing/log/test_log.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import py
import sys

import pytest
from py._log.log import default_keywordmapper

callcapture = py.io.StdCapture.call

default_keywordmapper = pytest.importorskip('py._log.log.default_keywordmapper')

def setup_module(mod):
mod._oldstate = default_keywordmapper.getstate()
Expand Down
4 changes: 0 additions & 4 deletions testing/root/test_py_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

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


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

Expand Down

0 comments on commit b94cb38

Please sign in to comment.