From 15dd32c62eccb74f95c73c0bf247b525453087f1 Mon Sep 17 00:00:00 2001 From: Andrei Zhlobich Date: Fri, 7 May 2021 13:26:03 +0200 Subject: [PATCH 1/4] Use 'pytest' to run tests via github-actions --- .github/workflows/python-app.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 501a9e1c..2e637b4b 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -45,6 +45,4 @@ jobs: - name: Tests run: | - python -m unittest discover -s bigflow -t . -p '*.py' - python -m unittest discover -s test -p '*.py' - + pytest From 88ab81e4d7bdfb33a35a5ba93c2fafb4ff43672d Mon Sep 17 00:00:00 2001 From: Andrei Zhlobich Date: Fri, 7 May 2021 13:27:40 +0200 Subject: [PATCH 2/4] Refactor github workflow - move deps to requirements.txt --- .github/workflows/python-app.yml | 9 ++------- requirements.txt | 4 +++- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 2e637b4b..fcc2fdfd 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -24,24 +24,19 @@ jobs: run: | git config --global user.email "fake@example.com" git config --global user.name "fake name" + - name: Setup docker run: | sudo apt install apt-transport-https ca-certificates curl software-properties-common curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic test" sudo apt update - sudo apt install docker-ce + sudo apt install docker-ce docker docker -v - name: Install dependencies run: | - python -m pip install --upgrade pip - pip install bs4 - pip install pytest - pip install bigflow pip install -r requirements.txt - pip install -r test/requirements.txt - sudo apt install docker - name: Tests run: | diff --git a/requirements.txt b/requirements.txt index 404bc95b..f37e2824 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,9 @@ -r requirements/log_extras.txt -r requirements/dataproc_extras.txt -r requirements/dataflow_extras.txt +pytest twine freezegun pexpect -responses \ No newline at end of file +responses +bs4 \ No newline at end of file From df316c84f27f11d5cbb30e0e0a8ce5701cc01439 Mon Sep 17 00:00:00 2001 From: Andrei Zhlobich Date: Tue, 11 May 2021 11:12:50 +0200 Subject: [PATCH 3/4] Github actions - Publish pytest html report, annotate fails --- .github/workflows/python-app.yml | 22 ++++++++++++++++------ pyproject.toml | 2 +- requirements.txt | 8 ++++++-- test/cli/__init__.py | 0 4 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 test/cli/__init__.py diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index fcc2fdfd..5bc8f1ec 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -11,15 +11,18 @@ on: jobs: build: - runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up Python 3.7 + + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup Python uses: actions/setup-python@v2 with: python-version: 3.7 + - name: Setup github username run: | git config --global user.email "fake@example.com" @@ -31,13 +34,20 @@ jobs: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic test" sudo apt update - sudo apt install docker-ce docker + sudo apt install docker-ce docker -v - name: Install dependencies run: | pip install -r requirements.txt - - name: Tests + - name: Run unit tests run: | - pytest + pytest --html=build/test-report.html --self-contained-html + + - name: Upload test report + if: always() + uses: actions/upload-artifact@v2 + with: + name: test-report + path: build/test-report.html diff --git a/pyproject.toml b/pyproject.toml index 194fa38b..994bb1b0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.pytest.ini_options] minversion = "6.0" -#addopts = "-ra -q" testpaths = [ "test", + "bigflow", ] diff --git a/requirements.txt b/requirements.txt index f37e2824..04e00434 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,9 +4,13 @@ -r requirements/log_extras.txt -r requirements/dataproc_extras.txt -r requirements/dataflow_extras.txt -pytest twine freezegun pexpect responses -bs4 \ No newline at end of file +bs4 + +pytest +pytest-html +pytest-cov +pytest-github-actions-annotate-failures \ No newline at end of file diff --git a/test/cli/__init__.py b/test/cli/__init__.py new file mode 100644 index 00000000..e69de29b From 112a0cf92f80ca38b527dc2916964e12a2708fa3 Mon Sep 17 00:00:00 2001 From: Andrei Zhlobich Date: Mon, 7 Jun 2021 18:28:58 +0200 Subject: [PATCH 4/4] Fixup test_cli.py - update sys.path --- test/cli/test_cli.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/test/cli/test_cli.py b/test/cli/test_cli.py index 6f618a9e..44f193d2 100644 --- a/test/cli/test_cli.py +++ b/test/cli/test_cli.py @@ -1,5 +1,3 @@ -from logging import shutdown -from mock.mock import _set_return_value from bigflow.build.operate import build_project from unittest import TestCase import itertools @@ -7,6 +5,7 @@ import shutil import freezegun +from bigflow.testing.isolate import ForkIsolateMixin from bigflow.cli import * from test import mixins @@ -16,12 +15,14 @@ class CliTestCase( mixins.PrototypedDirMixin, + ForkIsolateMixin, TestCase, ): proto_dir = "bf-projects/example_project" def setUp(self) -> None: super().setUp() + sys.path.append(str(Path(__file__).parent)) self.project_setuppy = self.cwd / "setup.py" @@ -30,12 +31,6 @@ def setUp(self) -> None: bigflow.build.spec.get_project_spec.cache_clear() - def tearDown(self): - try: - import_module("test_module.Unused1").started_jobs.clear() - except ImportError: - pass - def test_should_walk_through_all_files_inside_package_tree(self): # when res = walk_module_files(TEST_MODULE_PATH)