Skip to content

Commit

Permalink
Merge branch 'master' into feat/code-coverage-report
Browse files Browse the repository at this point in the history
Merged in PR spyder-ide#174, use the python interpreter from settings
  • Loading branch information
stevetracvc committed Jun 10, 2022
2 parents 9c910b3 + 0b25301 commit 2168e31
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 33 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/linux-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:
uses: actions/checkout@v2
- name: Install System Packages
run: |
sudo apt-get update
sudo apt-get install libegl1-mesa
sudo apt-get update --fix-missing
sudo apt-get install -qq pyqt5-dev-tools libxcb-xinerama0 xterm --fix-missing
- name: Install Conda
uses: conda-incubator/setup-miniconda@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion requirements/conda.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
lxml
spyder>=5.2,<6
spyder>=5.3.1,<6
2 changes: 1 addition & 1 deletion requirements/tests.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
codecov
flaky
nose
pytest
pytest>=5
pytest-cov
pytest-mock
pytest-qt
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_package_data(name, extlist):


# Requirements
REQUIREMENTS = ['lxml', 'spyder>=5.2,<6', 'pyzmq']
REQUIREMENTS = ['lxml', 'spyder>=5.3.1,<6', 'pyzmq']
EXTLIST = ['.jpg', '.png', '.json', '.mo', '.ini']
LIBNAME = 'spyder_unittest'

Expand Down
4 changes: 2 additions & 2 deletions spyder_unittest/backend/pytestrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ def create_argument_list(self, config, cov_path):
[f"--cov={cov_path}", "--cov-report=term-missing"]
if config.coverage else [])

def start(self, config, cov_path, pythonpath):
def start(self, config, cov_path, executable, pythonpath):
"""Start process which will run the unit test suite."""
self.config = config
self.reader = ZmqStreamReader()
self.reader.sig_received.connect(self.process_output)
RunnerBase.start(self, config, cov_path, pythonpath)
RunnerBase.start(self, config, cov_path, executable, pythonpath)

def process_output(self, output):
"""
Expand Down
22 changes: 10 additions & 12 deletions spyder_unittest/backend/pytestworker.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@
# Third party imports
import pytest

# Local imports
from spyder.config.base import get_translation
from spyder_unittest.backend.zmqstream import ZmqStreamWriter

# Local imports, needs to be relative otherwise it will fail if trying
# to execute in a different env with only spyder-kernel installed
try:
_ = get_translation('spyder_unittest')
except KeyError: # pragma: no cover
import gettext
_ = gettext.gettext

# this line is needed for the tests to succeed
from .zmqstream import ZmqStreamWriter
except:
# this line is needed for the plugin to work
from zmqstream import ZmqStreamWriter

class FileStub():
"""Stub for ZmqStreamWriter which instead writes to a file."""
Expand Down Expand Up @@ -104,8 +102,8 @@ def pytest_runtest_logreport(self, report):
self.was_skipped = True
if hasattr(report, 'wasxfail'):
self.was_xfail = True
self.longrepr.append(report.wasxfail if report.wasxfail else _(
'WAS EXPECTED TO FAIL'))
self.longrepr.append(report.wasxfail if report.wasxfail else
'WAS EXPECTED TO FAIL')
self.sections = report.sections # already accumulated over phases
if report.longrepr:
first_msg_idx = len(self.longrepr)
Expand All @@ -120,7 +118,7 @@ def pytest_runtest_logreport(self, report):
if report.outcome == 'failed' and report.when in (
'setup', 'teardown'):
self.longrepr[first_msg_idx] = '{} {}: {}'.format(
_('ERROR at'), report.when, self.longrepr[first_msg_idx])
'ERROR at', report.when, self.longrepr[first_msg_idx])

def pytest_runtest_logfinish(self, nodeid, location):
"""Called by pytest when the entire test is completed."""
Expand Down
6 changes: 3 additions & 3 deletions spyder_unittest/backend/runnerbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from qtpy.QtCore import (QObject, QProcess, QProcessEnvironment, QTextCodec,
Signal)
from spyder.py3compat import to_text_string
from spyder.utils.misc import get_python_executable

try:
from importlib.util import find_spec as find_spec_or_loader
Expand Down Expand Up @@ -189,7 +188,7 @@ def _prepare_process(self, config, pythonpath):
process.setProcessEnvironment(env)
return process

def start(self, config, cov_path, pythonpath):
def start(self, config, cov_path, executable, pythonpath):
"""
Start process which will run the unit test suite.
Expand All @@ -205,6 +204,8 @@ def start(self, config, cov_path, pythonpath):
Unit test configuration.
cov_path : str or None
Path to filter source for coverage report
executable : str
Path to Python executable
pythonpath : list of str
List of directories to be added to the Python path
Expand All @@ -214,7 +215,6 @@ def start(self, config, cov_path, pythonpath):
If process failed to start.
"""
self.process = self._prepare_process(config, pythonpath)
executable = get_python_executable()
p_args = self.create_argument_list(config, cov_path)
try:
os.remove(self.resultfilename)
Expand Down
8 changes: 5 additions & 3 deletions spyder_unittest/backend/tests/test_pytestrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
# Standard library imports
import os
import os.path as osp
import sys

# Third party imports
import pytest
from qtpy.QtCore import QByteArray

# Local imports
from spyder_unittest.backend.pytestrunner import (PyTestRunner,
Expand Down Expand Up @@ -61,13 +61,13 @@ def test_pytestrunner_start(monkeypatch):
runner = PyTestRunner(None, 'results')
config = Config()
cov_path = None
runner.start(config, cov_path, ['pythondir'])
runner.start(config, cov_path, sys.executable, ['pythondir'])
assert runner.config is config
assert runner.reader is mock_reader
runner.reader.sig_received.connect.assert_called_once_with(
runner.process_output)
MockRunnerBase.start.assert_called_once_with(
runner, config, cov_path, ['pythondir'])
runner, config, cov_path, sys.executable, ['pythondir'])


def test_pytestrunner_process_output_with_collected(qtbot):
Expand All @@ -79,6 +79,7 @@ def test_pytestrunner_process_output_with_collected(qtbot):
expected = ['spam.ham', 'eggs.bacon']
assert blocker.args == [expected]


def test_pytestrunner_process_output_with_collecterror(qtbot):
runner = PyTestRunner(None)
output = [{
Expand All @@ -91,6 +92,7 @@ def test_pytestrunner_process_output_with_collecterror(qtbot):
expected = [('ham.spam', 'msg')]
assert blocker.args == [expected]


def test_pytestrunner_process_output_with_starttest(qtbot):
runner = PyTestRunner(None)
output = [{'event': 'starttest', 'nodeid': 'ham/spam.py::ham'},
Expand Down
8 changes: 2 additions & 6 deletions spyder_unittest/backend/tests/test_runnerbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,14 @@ def test_runnerbase_start(monkeypatch):
monkeypatch.setattr('spyder_unittest.backend.runnerbase.os.remove',
mock_remove)

monkeypatch.setattr(
'spyder_unittest.backend.runnerbase.get_python_executable',
lambda: 'python')

runner = RunnerBase(None, 'results')
runner._prepare_process = lambda c, p: mock_process
runner.create_argument_list = lambda c, cp: ['arg1', 'arg2']
config = Config('pytest', 'wdir', False)
cov_path = None
mock_process.waitForStarted = lambda: False
with pytest.raises(RuntimeError):
runner.start(config, cov_path, ['pythondir'])
runner.start(config, cov_path, 'python_exec', ['pythondir'])

mock_process.start.assert_called_once_with('python', ['arg1', 'arg2'])
mock_process.start.assert_called_once_with('python_exec', ['arg1', 'arg2'])
mock_remove.assert_called_once_with('results')
5 changes: 5 additions & 0 deletions spyder_unittest/widgets/tests/test_unittestgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# Standard library imports
import os
import sys

# Third party imports
from qtpy.QtCore import Qt, QProcess
Expand All @@ -26,6 +27,10 @@
@pytest.fixture
def widget(qtbot):
unittest_widget = UnitTestWidget('testwidget', None, None)
unittest_widget.get_conf(
'executable',
section='main_interpreter',
default=sys.executable)
unittest_widget.setup()
qtbot.addWidget(unittest_widget)
return unittest_widget
Expand Down
4 changes: 2 additions & 2 deletions spyder_unittest/widgets/unittestgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,9 @@ def run_tests(self, config=None):
section='project_explorer')
# config returns 'None' as a string rather than None
cov_path = config.wdir if cov_path == 'None' else cov_path

executable = self.get_conf('executable', section='main_interpreter')
try:
self.testrunner.start(config, cov_path, pythonpath)
self.testrunner.start(config, cov_path, executable, pythonpath)
except RuntimeError:
QMessageBox.critical(self,
_("Error"), _("Process failed to start"))
Expand Down

0 comments on commit 2168e31

Please sign in to comment.