Default to not using the clipboard during tests.

master
Pacman Ghost 6 years ago
parent fd3285b561
commit 7e2c173313
  1. 12
      conftest.py
  2. 6
      vasl_templates/webapp/tests/utils.py

@ -42,9 +42,13 @@ def pytest_addoption( parser ):
"--short-tests", action="store_true", dest="short_tests", default=False,
help="Run a shorter version of the test suite."
)
# NOTE: It's not good to have the code run differently to how it will normally,
# but using the clipboard to retrieve snippets causes more trouble than it's worth :-/
# since any kind of clipboard activity while the tests are running could cause them to fail
# (even when running in a VM, if it's configured to share the physical host's clipboard :wall:).
parser.addoption(
"--no-clipboard", action="store_true", dest="no_clipboard", default=False,
help="Don't use the clipboard to get snippets."
"--use-clipboard", action="store_true", dest="use_clipboard", default=False,
help="Use the clipboard to get snippets."
)
# ---------------------------------------------------------------------
@ -67,9 +71,9 @@ def webapp():
# check if the tests are being run headless
if pytest.config.option.headless: #pylint: disable=no-member
# yup - there is no clipboard support :-/
pytest.config.option.no_clipboard = True #pylint: disable=no-member
pytest.config.option.use_clipboard = False #pylint: disable=no-member
# check if we should disable using the clipboard for snippets
if pytest.config.option.no_clipboard: #pylint: disable=no-member
if not pytest.config.option.use_clipboard: #pylint: disable=no-member
# NOTE: It's not a bad idea to bypass the clipboard, even when running in a browser,
# to avoid problems if something else uses the clipboard while the tests are running.
kwargs["store_clipboard"] = 1

@ -350,14 +350,14 @@ _pyqt_app = None
def get_clipboard() :
"""Get the contents of the clipboard."""
if pytest.config.option.no_clipboard: #pylint: disable=no-member
return get_stored_msg( "_clipboard_" )
else:
if pytest.config.option.use_clipboard: #pylint: disable=no-member
global _pyqt_app
if _pyqt_app is None:
_pyqt_app = QApplication( [] )
clipboard = QApplication.clipboard()
return clipboard.text()
else:
return get_stored_msg( "_clipboard_" )
def wait_for( timeout, func ):
"""Wait for a condition to become true."""

Loading…
Cancel
Save