From acd41b3b70026c6661ab25157944a8944e68a9e0 Mon Sep 17 00:00:00 2001 From: Saptak S Date: Thu, 2 Apr 2020 04:19:50 +0530 Subject: [PATCH] Adds bash script to run GUI tests individually --- .circleci/config.yml | 2 +- BUILD.md | 8 ++++---- tests/gui_base_test.py | 1 + tests/run.sh | 26 ++++++++++++++++++++++++++ 4 files changed, 32 insertions(+), 5 deletions(-) create mode 100755 tests/run.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index 8f8a51cc..dd84e371 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -51,7 +51,7 @@ jobs: - run: name: Run unit tests command: | - xvfb-run -s "-screen 0 1280x1024x24" poetry run pytest --rungui -vvv --no-qt-log tests/ + xvfb-run -s "-screen 0 1280x1024x24" poetry run ./tests/run.sh --rungui test-3.7: <<: *test-template diff --git a/BUILD.md b/BUILD.md index b631d410..fd7e9ebe 100644 --- a/BUILD.md +++ b/BUILD.md @@ -267,19 +267,19 @@ This will prompt you to codesign three binaries and execute one unsigned binary. OnionShare includes PyTest unit tests. To run tests, you can run `pytest` against the `tests/` directory. ```sh -poetry run pytest tests/ +poetry run ./tests/run.sh ``` You can run GUI tests like this: ```sh -poetry run pytest --rungui tests/ +poetry run ./tests/run.sh --rungui ``` If you would like to also run the GUI unit tests in 'tor' mode, start Tor Browser in the background, then run: ```sh -poetry run pytest --rungui --runtor tests/ +poetry run ./tests/run.sh --rungui --runtor ``` Keep in mind that the Tor tests take a lot longer to run than local mode, but they are also more comprehensive. @@ -287,7 +287,7 @@ Keep in mind that the Tor tests take a lot longer to run than local mode, but th You can also choose to wrap the tests in `xvfb-run` so that a ton of OnionShare windows don't pop up on your desktop (you may need to install the `xorg-x11-server-Xvfb` package), like this: ```sh -xvfb-run poetry run pytest --rungui -vvv --no-qt-log tests/ +xvfb-run poetry run ./tests/run.sh --rungui ``` # Making releases diff --git a/tests/gui_base_test.py b/tests/gui_base_test.py index c33891df..87353cd7 100644 --- a/tests/gui_base_test.py +++ b/tests/gui_base_test.py @@ -71,6 +71,7 @@ class GuiBaseTest(unittest.TestCase): @classmethod def tearDownClass(cls): # Quit + cls.gui.qtapp.clipboard().clear() QtCore.QTimer.singleShot(200, cls.gui.close_dialog.accept_button.click) cls.gui.close() diff --git a/tests/run.sh b/tests/run.sh new file mode 100755 index 00000000..3c792cd3 --- /dev/null +++ b/tests/run.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# The script runs python tests +# Firstly, all CLI tests are run +# Then, all the GUI tests are run individually +# to avoid segmentation fault + +PARAMS="" + +while [ ! $# -eq 0 ] +do + case "$1" in + --rungui) + PARAMS="$PARAMS --rungui" + ;; + --runtor) + PARAMS="$PARAMS --runtor" + ;; + esac + shift +done + +pytest $PARAMS -vvv ./tests/test_cli*.py +for filename in ./tests/test_gui_*.py; do + pytest $PARAMS -vvv --no-qt-log $filename +done