From ad3067e2c29053ca07e64e1b4ccdb9b802cabc8b Mon Sep 17 00:00:00 2001 From: Jonatan Heyman Date: Fri, 22 Jan 2021 13:45:48 +0100 Subject: [PATCH 1/4] Use Github Actions for CI --- .github/workflows/tests.yml | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000000..2d1a3a6488 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,44 @@ +name: Tests + +on: [push, pull_request] + +jobs: + tests: + name: ${{ matrix.name }} + runs-on: ${{ matrix.os }} + + strategy: + fail-fast: false + matrix: + include: + #- {name: Linux, python: '3.9', os: ubuntu-latest, tox: py39} + #- {name: Windows, python: '3.9', os: windows-latest, tox: py39} + #- {name: Mac, python: '3.9', os: macos-latest, tox: py39} + - {name: '3.9', python: '3.9', os: ubuntu-latest, tox: py39} + - {name: '3.8', python: '3.8', os: ubuntu-latest, tox: py38} + - {name: '3.7', python: '3.7', os: ubuntu-latest, tox: py37} + - {name: '3.6', python: '3.6', os: ubuntu-latest, tox: py36} + + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python }} + - name: Update pip + run: | + pip install -U wheel + pip install -U setuptools + python -m pip install -U pip + - name: Get pip cache dir + id: pip-cache + run: echo "::set-output name=dir::$(pip cache dir)" + - name: Cache pip + uses: actions/cache@v2 + with: + path: ${{ steps.pip-cache.outputs.dir }} + key: pip|${{ runner.os }}|${{ matrix.python }}|${{ hashFiles('setup.py') }} + - name: set full Python version in PY env var + # See https://pre-commit.com/#github-actions-example + run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV + - run: pip install tox codecov + - run: tox -e ${{ matrix.tox }} From ae3a0286ee9d6dc2e8fa32ce93ab2c17bc1cff91 Mon Sep 17 00:00:00 2001 From: Jonatan Heyman Date: Fri, 22 Jan 2021 15:01:06 +0100 Subject: [PATCH 2/4] Use textwrap.dedent() for cleaner test code --- locust/test/test_main.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/locust/test/test_main.py b/locust/test/test_main.py index 869702971f..8bd2ab4c8f 100644 --- a/locust/test/test_main.py +++ b/locust/test/test_main.py @@ -255,17 +255,16 @@ def test_headless_spawn_options_wo_run_time(self): self.assertIn("Shutting down (exit code 0), bye", stderr) def test_default_headless_spawn_options_with_shape(self): - content = ( - MOCK_LOUCSTFILE_CONTENT - + """ -class LoadTestShape(LoadTestShape): - def tick(self): - run_time = self.get_run_time() - if run_time < 2: - return (10, 1) - - return None - """ + content = MOCK_LOUCSTFILE_CONTENT + textwrap.dedent( + """ + class LoadTestShape(LoadTestShape): + def tick(self): + run_time = self.get_run_time() + if run_time < 2: + return (10, 1) + + return None + """ ) with mock_locustfile(content=content) as mocked: output = ( From c7619bd700716d36ae6e42827cf14a9c11e69576 Mon Sep 17 00:00:00 2001 From: Jonatan Heyman Date: Fri, 22 Jan 2021 15:46:07 +0100 Subject: [PATCH 3/4] Remove check for "Quitting..." that won't be printed when running with LocalRunner --- locust/test/test_main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/locust/test/test_main.py b/locust/test/test_main.py index 8bd2ab4c8f..1452e86f69 100644 --- a/locust/test/test_main.py +++ b/locust/test/test_main.py @@ -278,7 +278,6 @@ def tick(self): ) self.assertIn("Shape test updating to 10 users at 1.00 spawn rate", output) self.assertIn("Cleaning up runner...", output) - self.assertIn("Quitting...", output) def test_web_options(self): port = get_free_tcp_port() From cb56d64f158bd8df2d833b9f252836d19dd39fbe Mon Sep 17 00:00:00 2001 From: Jonatan Heyman Date: Fri, 22 Jan 2021 15:46:54 +0100 Subject: [PATCH 4/4] Fix UnicodeEncodeError when writing HTML report --- locust/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locust/main.py b/locust/main.py index 1b3aceece3..5add22205a 100644 --- a/locust/main.py +++ b/locust/main.py @@ -426,7 +426,7 @@ def sig_term_handler(): main_greenlet.join() if options.html_file: html_report = get_html_report(environment, show_download_link=False) - with open(options.html_file, "w+") as file: + with open(options.html_file, "w", encoding="utf-8") as file: file.write(html_report) shutdown() except KeyboardInterrupt: