- Add patch to work with python-virtualenv >= 20:
* virtualenv-20.patch OBS-URL: https://build.opensuse.org/package/show/devel:languages:python:pytest/python-pytest-console-scripts?expand=0&rev=10
This commit is contained in:
parent
78d4c024a1
commit
1f43fdfbc0
@ -1,3 +1,9 @@
|
||||
-------------------------------------------------------------------
|
||||
Mon Apr 6 08:19:12 UTC 2020 - Tomáš Chvátal <tchvatal@suse.com>
|
||||
|
||||
- Add patch to work with python-virtualenv >= 20:
|
||||
* virtualenv-20.patch
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Fri Nov 15 10:41:07 UTC 2019 - Tomáš Chvátal <tchvatal@suse.com>
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#
|
||||
# spec file for package python-pytest-console-scripts
|
||||
#
|
||||
# Copyright (c) 2019 SUSE LLC.
|
||||
# Copyright (c) 2020 SUSE LLC
|
||||
#
|
||||
# All modifications and additions to the file contributed by third parties
|
||||
# remain the property of their copyright owners, unless otherwise agreed
|
||||
@ -17,14 +17,15 @@
|
||||
|
||||
|
||||
%{?!python_module:%define python_module() python-%{**} python3-%{**}}
|
||||
%define skip_python2 1
|
||||
Name: python-pytest-console-scripts
|
||||
Version: 0.2.0
|
||||
Release: 0
|
||||
Summary: Pytest plugin for testing console scripts
|
||||
License: MIT
|
||||
Group: Development/Languages/Python
|
||||
URL: https://github.com/kvas-it/pytest-console-scripts
|
||||
Source: https://files.pythonhosted.org/packages/source/p/pytest-console-scripts/pytest-console-scripts-%{version}.tar.gz
|
||||
Patch0: virtualenv-20.patch
|
||||
BuildRequires: %{python_module setuptools}
|
||||
BuildRequires: fdupes
|
||||
BuildRequires: python-rpm-macros
|
||||
@ -37,7 +38,7 @@ BuildRequires: %{python_module mock >= 2.0.0}
|
||||
BuildRequires: %{python_module pytest >= 4.0.0}
|
||||
BuildRequires: %{python_module pytest-runner}
|
||||
BuildRequires: %{python_module pytest}
|
||||
BuildRequires: %{python_module virtualenv}
|
||||
BuildRequires: %{python_module virtualenv >= 20}
|
||||
# /SECTION
|
||||
%python_subpackages
|
||||
|
||||
|
106
virtualenv-20.patch
Normal file
106
virtualenv-20.patch
Normal file
@ -0,0 +1,106 @@
|
||||
From 3ee9419066c5d789854b55112472444053d4c7b5 Mon Sep 17 00:00:00 2001
|
||||
From: Vasily Kuznetsov <kvas.it@gmail.com>
|
||||
Date: Fri, 13 Mar 2020 16:18:24 +0100
|
||||
Subject: [PATCH] Update the tests and make them compatible with virtualenv
|
||||
v.20 (#31)
|
||||
|
||||
---
|
||||
pytest_console_scripts.py | 5 ++++-
|
||||
tests/test_run_scripts.py | 33 +++++++++++++++++++++++++--------
|
||||
4 files changed, 42 insertions(+), 13 deletions(-)
|
||||
|
||||
diff --git a/pytest_console_scripts.py b/pytest_console_scripts.py
|
||||
index dbeb5ee..a5c0c1e 100644
|
||||
--- a/pytest_console_scripts.py
|
||||
+++ b/pytest_console_scripts.py
|
||||
@@ -146,7 +146,10 @@ def _restore_logger(self, config):
|
||||
|
||||
def run_inprocess(self, command, *arguments, **options):
|
||||
cmdargs = [command] + list(arguments)
|
||||
- script = py.path.local(distutils.spawn.find_executable(command))
|
||||
+ script_path = distutils.spawn.find_executable(command)
|
||||
+ if script_path is None:
|
||||
+ raise FileNotFoundError('Cannot execute ' + command)
|
||||
+ script = py.path.local(script_path)
|
||||
stdin = options.get('stdin', StreamMock())
|
||||
stdout = StreamMock()
|
||||
stderr = StreamMock()
|
||||
diff --git a/tests/test_run_scripts.py b/tests/test_run_scripts.py
|
||||
index 2a0a9d2..3f76d5d 100644
|
||||
--- a/tests/test_run_scripts.py
|
||||
+++ b/tests/test_run_scripts.py
|
||||
@@ -1,9 +1,8 @@
|
||||
+import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
-import mock
|
||||
-import py
|
||||
import pytest
|
||||
import virtualenv
|
||||
|
||||
@@ -32,6 +31,7 @@ def __init__(self, path):
|
||||
dpp = self._distpackages_path()
|
||||
if dpp is not None:
|
||||
self.path.mkdir(dpp)
|
||||
+ self.sys_path = self._get_sys_path()
|
||||
|
||||
def _distpackages_path(self):
|
||||
"""Return (relative) path used for installing distribution packages.
|
||||
@@ -51,18 +51,33 @@ def _distpackages_path(self):
|
||||
parts = parts[parts.index('lib'):]
|
||||
return os.path.join(*parts)
|
||||
|
||||
- def _update_env(self, env):
|
||||
+ def _get_sys_path(self):
|
||||
+ """Return sys.path of this virtualenv."""
|
||||
+ result = self.run([
|
||||
+ 'python', '-c',
|
||||
+ 'import json,sys; print(json.dumps(sys.path))',
|
||||
+ ], skip_pythonpath=True)
|
||||
+ assert result.returncode == 0
|
||||
+ return json.loads(str(result.stdout.read(), encoding='utf-8'))
|
||||
+
|
||||
+ def _update_env(self, env, skip_pythonpath=False):
|
||||
bin_dir = self.path.join('bin').strpath
|
||||
env['PATH'] = bin_dir + ':' + env.get('PATH', '')
|
||||
+ if 'PYTHONHOME' in env:
|
||||
+ del env['PYTHONHOME']
|
||||
env['VIRTUAL_ENV'] = self.path.strpath
|
||||
+ if skip_pythonpath:
|
||||
+ return
|
||||
# Make installed packages of the Python installation that runs this
|
||||
# test accessible. This allows us to run tests in the virtualenv
|
||||
# without installing all the dependencies there.
|
||||
- env['PYTHONPATH'] = ':'.join(sys.path)
|
||||
+ python_path = set(sys.path + self.sys_path)
|
||||
+ env['PYTHONPATH'] = ':'.join(python_path)
|
||||
|
||||
- def run(self, cmd, *args, **kw):
|
||||
+ def run(self, cmd, skip_pythonpath=False, *args, **kw):
|
||||
"""Run a command in the virtualenv, return terminated process."""
|
||||
- self._update_env(kw.setdefault('env', dict(os.environ)))
|
||||
+ self._update_env(kw.setdefault('env', dict(os.environ)),
|
||||
+ skip_pythonpath=skip_pythonpath)
|
||||
kw.setdefault('stdout', subprocess.PIPE)
|
||||
kw.setdefault('stderr', subprocess.PIPE)
|
||||
proc = subprocess.Popen(cmd, *args, **kw)
|
||||
@@ -75,14 +90,16 @@ def install_console_script(self, cmd, script_path):
|
||||
script_name = script_path.purebasename
|
||||
setup_py = script_dir.join('setup.py')
|
||||
setup_py.write(SETUP_TEMPLATE.format(cmd=cmd, script_name=script_name))
|
||||
- self.run(['python', 'setup.py', 'develop'], cwd=str(script_dir))
|
||||
+ result = self.run(['python', 'setup.py', 'develop'],
|
||||
+ cwd=str(script_dir), skip_pythonpath=True)
|
||||
+ assert result.returncode == 0
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def pcs_venv(tmpdir_factory):
|
||||
"""Virtualenv for testing console scripts."""
|
||||
venv = tmpdir_factory.mktemp('venv')
|
||||
- virtualenv.create_environment(venv.strpath)
|
||||
+ virtualenv.cli_run([venv.strpath])
|
||||
yield VEnvWrapper(venv)
|
||||
|
Loading…
Reference in New Issue
Block a user