Skip to content

Commit

Permalink
deps: removed dependency on "py" package
Browse files Browse the repository at this point in the history
- no need to import Source from py library (it's enough to dedent)
- no need to use obsolete py.path.local, using pathlib.Path instead
  • Loading branch information
aurzenligl committed Feb 19, 2024
1 parent 7c6e964 commit d178456
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 24 deletions.
1 change: 0 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
py==1.11.0
pytest==7.4.4
sphinx==7.2.6
sphinx_rtd_theme==2.0.0
32 changes: 16 additions & 16 deletions pytest_logger/plugin.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import os
import sys
import re
import py
import pytest
import logging
import time
import datetime
import argparse
import shutil
from builtins import object, int
from pathlib import Path


def pytest_addhooks(pluginmanager):
Expand Down Expand Up @@ -107,13 +108,13 @@ def pytest_runtest_makereport(self, item, call):
logger = getattr(item, '_logger', None)
if logger:
if self._logsdir and self._split_by_outcome_subdir and tr.outcome in self._split_by_outcome_outcomes:
split_by_outcome_logdir = self._logsdir.join(self._split_by_outcome_subdir, tr.outcome)
split_by_outcome_logdir = self._logsdir / self._split_by_outcome_subdir / tr.outcome
nodeid = _sanitize_nodeid(item.nodeid)
nodepath = os.path.dirname(nodeid)
split_by_outcome_logdir.join(nodepath).ensure(dir=1)
destdir_relpath = os.path.relpath(str(self._logsdir.join(nodeid)),
str(split_by_outcome_logdir.join(nodepath)))
_refresh_link(destdir_relpath, str(split_by_outcome_logdir.join(nodeid)))
outcomedir = split_by_outcome_logdir / nodepath
outcomedir.mkdir(parents=True, exist_ok=True)
destdir_relpath = os.path.relpath(self._logsdir / nodeid, outcomedir)
_refresh_link(destdir_relpath, split_by_outcome_logdir / nodeid)
if call.when == 'teardown':
logger.on_makereport()

Expand Down Expand Up @@ -356,21 +357,20 @@ def _make_logsdir_tmpdir(tmpdirhandler):
if logsdir.basename.startswith('popen-gw'):
logsdir = logsdir.join('..')
logsdir = logsdir.join('logs').ensure(dir=1)
return logsdir
return Path(logsdir)


def _make_logsdir_dir(dstname, cleandir=True):
logsdir = py.path.local(dstname)
if cleandir:
if logsdir.check():
logsdir.remove()
logsdir.mkdir()
return logsdir
def _make_logsdir_dir(dstname):
shutil.rmtree(dstname, ignore_errors=True)
os.mkdir(dstname)
return Path(dstname)


def _make_logdir(item):
plugin = item.config.pluginmanager.getplugin('_logger')
return plugin.logsdir().join(_sanitize_nodeid(item.nodeid)).ensure(dir=1)
logdir = plugin.logsdir() / _sanitize_nodeid(item.nodeid)
logdir.mkdir(parents=True)
return logdir


def _enable(handlers):
Expand Down Expand Up @@ -485,7 +485,7 @@ def make_handler(logdir, logger_and_level, fmt):
name, level = logger_and_level
logger = logging.getLogger(name)
name = name or 'logs'
logfile = str(logdir.join(name))
logfile = str(logdir / name)
handler = logging.FileHandler(filename=logfile, mode='w', delay=True)
handler.setFormatter(fmt)
handler.setLevel(level)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def read(fname):
long_description=read('README.rst'),
long_description_content_type='text/x-rst',
packages=['pytest_logger'],
install_requires=['pytest>=3.2', 'py'],
install_requires=['pytest>=3.2'],
keywords='py.test pytest logging',
classifiers=[
'Development Status :: 5 - Production/Stable',
Expand Down
11 changes: 5 additions & 6 deletions tests/test_pytest_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
import sys
import pytest
import platform
from py.code import Source
from _pytest.pytester import LineMatcher
import textwrap

win32 = sys.platform == 'win32'
win32py2 = win32 and sys.version_info[0] == 2
win32pypy = win32 and platform.python_implementation() == 'PyPy'


def makefile(testdir, path, content):
return testdir.tmpdir.ensure(*path).write('\n'.join(Source(content)))
return testdir.tmpdir.ensure(*path).write(textwrap.dedent(content))


def ls(dir, filepath=''):
Expand Down Expand Up @@ -64,10 +63,10 @@ def test_case():
return filename


class FileLineMatcher(LineMatcher):
class FileLineMatcher(pytest.LineMatcher):
def __init__(self, dir, filepath):
lines = dir.join(filepath).read().splitlines()
LineMatcher.__init__(self, lines)
pytest.LineMatcher.__init__(self, lines)


def test_logdir_fixture(testdir):
Expand Down Expand Up @@ -566,7 +565,7 @@ def test_logsdir_cleanup(testdir, conftest_py, test_case_py):
logger_logsdir={0}
""".format(logsdir))

logsdir.ensure('tmpfile').write('\n'.join(Source('this shall be removed')))
logsdir.ensure('tmpfile').write(textwrap.dedent('this shall be removed'))
logsdir.join('tmpdir')

result = testdir.runpytest('-s')
Expand Down

0 comments on commit d178456

Please sign in to comment.