Skip to content

Fix py.log import error on Windows due to syslog #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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