Skip to content
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

PR: Use the Python interpreter set in Preferences to run tests #174

Merged
merged 27 commits into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e8d6dd1
feat: allow user to pick a different python for running tests
stevetracvc Apr 16, 2022
e54857c
feat: validate chosen python executable
stevetracvc Apr 17, 2022
fa4a74c
fix: try spyder get_translation import, then fall back to gettext
stevetracvc Apr 20, 2022
1152930
fix: relative import of ZmqStreamWriter
stevetracvc Apr 23, 2022
b060203
fix: config dialog test fix
stevetracvc Apr 23, 2022
7ae8b3b
fix: more issues with zmq
stevetracvc Apr 23, 2022
af7bb84
new tests for config dialog
stevetracvc Apr 25, 2022
5b58ef6
removed text translation code
stevetracvc Apr 25, 2022
0411d39
fix: store pyexec in config file
stevetracvc Apr 25, 2022
c70b410
Use Python interpreter from Spyder preferences by default
jitseniesen Apr 28, 2022
6dda2b8
fix: store empty string in project config if no pyexec chosen
stevetracvc May 1, 2022
97a22f5
moved on_interpreter_config_change to UnitTestWidget
stevetracvc May 15, 2022
466798d
removed manual pyexec config option
stevetracvc May 15, 2022
8509737
upgraded to spyder 5.3.1 for get_conf
stevetracvc May 31, 2022
e2ab7a2
fixed testing issues
stevetracvc Jun 1, 2022
d349c7c
another test skipped
stevetracvc Jun 1, 2022
9ba80c6
skipping another test
stevetracvc Jun 1, 2022
c07ea16
attempt newer pytest-qt for testing
stevetracvc Jun 2, 2022
01b73c9
skipping all qtbot tests
stevetracvc Jun 2, 2022
c2bbe2b
attempt to fix segfaults on linux tests
stevetracvc Jun 2, 2022
c7abea1
Revert "skipping all qtbot tests"
stevetracvc Jun 2, 2022
323617b
Revert "attempt newer pytest-qt for testing"
stevetracvc Jun 2, 2022
9b05ea6
Revert "skipping another test"
stevetracvc Jun 2, 2022
f9ea870
Revert "another test skipped"
stevetracvc Jun 2, 2022
c4bb682
fixed segfaults, no longer need to skip qtbot tests
stevetracvc Jun 2, 2022
c3102c1
bumped pytest requirements to version 5
stevetracvc Jun 2, 2022
6642de0
fixed some comments
stevetracvc Jun 7, 2022
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
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 @@ -45,12 +45,12 @@ def create_argument_list(self):
pyfile = os.path.join(os.path.dirname(__file__), 'pytestworker.py')
return [pyfile, str(self.reader.port)]

def start(self, config, pythonpath):
def start(self, config, 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, pythonpath)
RunnerBase.start(self, config, 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, pythonpath):
def start(self, config, executable, pythonpath):
"""
Start process which will run the unit test suite.

Expand All @@ -203,6 +202,8 @@ def start(self, config, pythonpath):
----------
config : TestConfig
Unit test configuration.
executable : str
Path to Python executable
pythonpath : list of str
List of directories to be added to the Python path

Expand All @@ -212,7 +213,6 @@ def start(self, config, pythonpath):
If process failed to start.
"""
self.process = self._prepare_process(config, pythonpath)
executable = get_python_executable()
p_args = self.create_argument_list()
try:
os.remove(self.resultfilename)
Expand Down
9 changes: 6 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 @@ -58,12 +58,13 @@ def test_pytestrunner_start(monkeypatch):

runner = PyTestRunner(None, 'results')
config = Config()
runner.start(config, ['pythondir'])
runner.start(config, 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, ['pythondir'])
MockRunnerBase.start.assert_called_once_with(
runner, config, sys.executable, ['pythondir'])


def test_pytestrunner_process_output_with_collected(qtbot):
Expand All @@ -75,6 +76,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 @@ -87,6 +89,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 @@ -76,17 +76,13 @@ 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: ['arg1', 'arg2']
config = Config('pytest', 'wdir')
mock_process.waitForStarted = lambda: False
with pytest.raises(RuntimeError):
runner.start(config, ['pythondir'])
runner.start(config, '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 @@ -340,9 +340,9 @@ def run_tests(self, config=None):
self.testrunner.sig_starttest.connect(self.tests_started)
self.testrunner.sig_testresult.connect(self.tests_yield_result)
self.testrunner.sig_stop.connect(self.tests_stopped)

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