From c0595bac1e4e5aaa59529281a4472349a084c819 Mon Sep 17 00:00:00 2001 From: Reillyhewitson Date: Mon, 12 Dec 2022 16:16:32 +0000 Subject: [PATCH] Split unit and integration test runs --- .github/workflows/ci-build.yml | 58 +++++++++++++++++++--------------- noxfile.py | 24 ++++++++++++-- poetry.lock | 2 +- pyproject.toml | 2 +- 4 files changed, 56 insertions(+), 30 deletions(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 048e15cd..fc58071c 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -29,8 +29,36 @@ jobs: python-version: ${{ matrix.python-version }} architecture: x64 + # Install Nox, Poetry and API's dependencies + - name: Install Nox + run: pip install nox==2020.8.22 + - name: Install Poetry + run: pip install poetry==1.1.9 + + # Installing an older version of setuptools for reasons explained at: https://github.com/icatproject/python-icat/issues/99 + - name: Uninstall setuptools + run: poetry run pip uninstall -y setuptools + - name: Install older setuptools + run: poetry run pip install 'setuptools<58.0.0' + + # This command is a workaround for getting Poetry working with Python 3.10. An + # fix is made in Poetry 1.2.0a2 but there is currently no official release for + # Poetry 1.2 and am apprehensive to moving to a pre-release. Disabling the + # experimental installer is a workaround for Poetry 1.1.x + # See https://github.com/python-poetry/poetry/issues/4210 for more details + - name: Disable Poetry's experimental new installer + run: poetry config experimental.new-installer false + + - name: Install dependencies + run: poetry install + + # Run Unit tests + - name: Run Nox unit tests session + run: nox -p ${{ matrix.python-version }} -s unit_tests -- --cov=datagateway_api --cov-report=xml + # ICAT Ansible clone and install dependencies - name: Checkout icat-ansible + if: success() uses: actions/checkout@v2 with: repository: icatproject-contrib/icat-ansible @@ -94,36 +122,14 @@ jobs: - name: Create search_api_mapping.json run: cp datagateway_api/search_api_mapping.json.example datagateway_api/search_api_mapping.json - # Install Nox, Poetry and API's dependencies - - name: Install Nox - run: pip install nox==2020.8.22 - - name: Install Poetry - run: pip install poetry==1.1.9 - - # Installing an older version of setuptools for reasons explained at: https://github.com/icatproject/python-icat/issues/99 - - name: Uninstall setuptools - run: poetry run pip uninstall -y setuptools - - name: Install older setuptools - run: poetry run pip install 'setuptools<58.0.0' - - # This command is a workaround for getting Poetry working with Python 3.10. An - # fix is made in Poetry 1.2.0a2 but there is currently no official release for - # Poetry 1.2 and am apprehensive to moving to a pre-release. Disabling the - # experimental installer is a workaround for Poetry 1.1.x - # See https://github.com/python-poetry/poetry/issues/4210 for more details - - name: Disable Poetry's experimental new installer - run: poetry config experimental.new-installer false - - - name: Install dependencies - run: poetry install - - name: Add dummy data to icatdb run: | poetry run python -m util.icat_db_generator - # Run Nox tests session, saves and uploads a coverage report to codecov - - name: Run Nox tests session - run: nox -p ${{ matrix.python-version }} -s tests -- --cov=datagateway_api --cov-report=xml + # Run Nox integration tests session, saves and uploads a coverage report to codecov + - name: Run Nox Integration tests session + if: success() + run: nox -p ${{ matrix.python-version }} -s integration_tests -- --cov=datagateway_api --cov-report=xml - name: Upload code coverage report if: matrix.python-version == '3.6' uses: codecov/codecov-action@v1 diff --git a/noxfile.py b/noxfile.py index 1ec9df25..2f749e89 100644 --- a/noxfile.py +++ b/noxfile.py @@ -95,7 +95,7 @@ def safety(session): @nox.session(python=["3.6", "3.7", "3.8", "3.9", "3.10"], reuse_venv=True) -def tests(session): +def unit_tests(session): args = session.posargs # Installing setuptools that will work with `2to3` which is used when building # `python-icat` < 1.0. 58.0.0 removes support of this tool during builds: @@ -111,4 +111,24 @@ def tests(session): # sign is specified for a package session.run("pip", "install", "setuptools<58.0.0") session.run("poetry", "install", external=True) - session.run("pytest", *args) + session.run("pytest", "test/unit", *args) + + +@nox.session(python=["3.6", "3.7", "3.8", "3.9", "3.10"], reuse_venv=True) +def integration_tests(session): + args = session.posargs + # Installing setuptools that will work with `2to3` which is used when building + # `python-icat` < 1.0. 58.0.0 removes support of this tool during builds: + # https://setuptools.pypa.io/en/latest/history.html#v58-0-0 + # Ideally this would be done within `pyproject.toml` but specifying `setuptools` as + # a dependency requires Poetry 1.2: + # https://github.com/python-poetry/poetry/issues/4511#issuecomment-922420457 + # Currently, only a pre-release exists for Poetry 1.2. Testing on the pre-release + # version didn't fix the `2to3` issue when building Python ICAT, perhaps because + # Python ICAT isn't built on the downgraded version for some reason? + session.run("pip", "uninstall", "-y", "setuptools") + # Not using `poetry run` as it errors on Windows OS when a version with the '<' + # sign is specified for a package + session.run("pip", "install", "setuptools<58.0.0") + session.run("poetry", "install", external=True) + session.run("pytest", "test/integration", *args) diff --git a/poetry.lock b/poetry.lock index b39ed41f..a1e4d2d7 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1279,7 +1279,7 @@ testing = ["pytest (>=4.6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytes [metadata] lock-version = "1.1" python-versions = ">=3.6.1,<4.0" -content-hash = "61ac95d09ddde72cadab31194a33d1fd79b68e3a771725db0f9ea627cc9f842c" +content-hash = "eeb4ff9346bd1d90ab3b7b6ea3cd2bdb14d1569a49c0ce5c2cc297c3b919b769" [metadata.files] aniso8601 = [] diff --git a/pyproject.toml b/pyproject.toml index 03f80450..13f8388c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,7 +26,7 @@ Flask-Cors = "3.0.9" apispec = "3.3.0" flask-swagger-ui = "3.25.0" PyYAML = "5.4" -python-icat = "0.21.0" +python-icat = "^0.21.0" suds-community = "^0.8.4" py-object-pool = "^1.1" cachetools = "^4.2.1"