Skip to content

Commit

Permalink
Merge branch 'tests/reorganise-tests#375' into tests/python_icatv1
Browse files Browse the repository at this point in the history
  • Loading branch information
Reillyhewitson authored Feb 1, 2023
2 parents a0e9527 + 35780bb commit fe6b137
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 25 deletions.
35 changes: 26 additions & 9 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,15 @@ jobs:
- 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
if: ${{ matrix.python-version == '3.10' }}
run: poetry config experimental.new-installer false

- name: Install dependencies
run: poetry install

# Prep for using the API for tests
- name: Create log file
run: touch logs.log
Expand Down Expand Up @@ -125,6 +117,31 @@ jobs:
run: |
cd /home/runner/install/icat.server/ && ./setup -vv install
- name: Checkout DataGateway API
uses: actions/checkout@v2

# Prep for using the API for tests
- name: Create log file
run: touch logs.log
- name: Configure log file location
run: echo "`yq \
'.log_location="${GITHUB_WORKSPACE}/logs.log"' datagateway_api/config.yaml.example | envsubst`" > datagateway_api/config.yaml.example
- name: Configure datagateway extension
run: echo "`yq \
'.datagateway_api.extension="/datagateway_api"' datagateway_api/config.yaml.example`" > datagateway_api/config.yaml.example
- name: Create config.yaml
run: cp datagateway_api/config.yaml.example datagateway_api/config.yaml
- name: Create search_api_mapping.json
run: cp datagateway_api/search_api_mapping.json.example datagateway_api/search_api_mapping.json

- name: Uninstall setuptools
run: poetry run pip uninstall -y setuptools
- name: Install older setuptools
run: poetry run pip install 'setuptools<58.0.0'

- name: Install dependencies
run: poetry install

- name: Add dummy data to icatdb
run: |
poetry run python -m util.icat_db_generator
Expand Down
39 changes: 26 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,12 @@ Currently, the following Nox sessions have been created:
- `safety` - this uses [safety](https://github.com/pyupio/safety) to check the
dependencies (pulled directly from Poetry) for any known vulnerabilities. This session
gives the output in a full ASCII style report.
- `tests` - this uses [pytest](https://docs.pytest.org/en/stable/) to execute the
automated tests in `test/`, tests for the database and ICAT backends, and non-backend
- `unit_tests` - this uses [pytest](https://docs.pytest.org/en/stable/) to execute the
automated tests in `test/unit`, tests for the database and ICAT backends, and non-backend
specific tests. More details about the tests themselves [here](#running-tests).
- `integration_tests` - this uses [pytest](https://docs.pytest.org/en/stable/) to execute the
automated tests in `test/unit`, tests for the database and ICAT backends, and non-backend
specific tests. Requires an ICAT backend. More details about the tests themselves [here](#running-tests).

Each Nox session builds an environment using the repo's dependencies (defined using
Poetry) using `install_with_constraints()`. This stores the dependencies in a
Expand Down Expand Up @@ -434,9 +437,14 @@ for the Swagger interface to be up to date when using the Python ICAT backend.

# Running Tests

To run the tests use `nox -s tests`. The repository contains a variety of tests, to test
the functionality of the API works as intended. The tests are split into 3 main
sections: non-backend specific (testing features such as the date handler), ICAT backend
There are two seperate test runners provided. The integration tests, and the unit tests.
The unit test do not require an ICAT stack to be setup to run. The integration tests do
require an ICAT stack. In order to cover all the code you will need to run both tests.

To run the unit test use `nox -s unit_tests`, and to run the integration tests use `nox -s integration_tests`
The repository contains a variety of tests, to test the functionality of the API works as intended, for convenience
and quicker action runs these are additionally split into the unit and integration tests.
The tests are split into 3 main sections: non-backend specific (testing features such as the date handler), ICAT backend
tests (containing tests for backend specific components, including tests for the
different types of endpoints) and Database Backend tests (like the ICAT backend tests,
but covering only the most used aspects of the API).
Expand All @@ -450,14 +458,16 @@ Python 3.6, 3.7, 3.8, 3.9 and 3.10. For most cases, running the tests in a singl
version will be sufficient:

```bash
nox -p 3.6 -s tests
nox -p 3.6 -s unit_tests
nox -p 3.6 -s integration
```

This repository also utilises [pytest-cov](https://pytest-cov.readthedocs.io/en/latest/)
to check how much of the codebase is covered by the tests in `test/`:

```bash
nox -p 3.6 -s tests -- --cov-report term --cov=./datagateway_api
nox -p 3.6 -s unit_tests -- --cov-report term --cov=./datagateway_api
nox -p 3.6 -s integration_tests -- --cov-report term --cov=./datagateway_api
```

With `pytest`, you can output the duration for each test, useful for showing the slower
Expand All @@ -466,21 +476,24 @@ into setup, call and teardown to more easily understand where the tests are bein
down:

```bash
nox -p 3.6 -s tests -- --durations=0
nox -p 3.6 -s unit_tests -- --durations=0
nox -p 3.6 -s integration_tests -- --durations=0
```

To test a specific test class (or even a specific test function), use a double colon to
denote a each level down beyond the filename:
To test a specific test class (or even a specific test function), you will
need to use pytest itself through poetry. If you want to change the python
version use `poetry env use 3.6` which will generate a virtual env with that
version.

```bash
# Test a specific file
nox -p 3.6 -s tests -- test/icat/test_query.py
poetry run pytest test/integration/datagateway_api/icat/test_query.py

# Test a specific test class
nox -p 3.6 -s tests -- test/icat/test_query.py::TestICATQuery
poetry run pytest test/integration/datagateway_api/icat/test_query.py::TestICATQuery

# Test a specific test function
nox -p 3.6 -s tests -- test/icat/test_query.py::TestICATQuery::test_valid_query_exeuction
poetry run pytest test/integration/datagateway_api/icat/test_query.py::TestICATQuery::test_valid_query_exeuction
```

# Project Structure
Expand Down
5 changes: 4 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def safety(session):
)
# Ignore 50916 as the latest version of pydantic and
# Ignore 51457 as the latest version of pytest and
# Ignore 51668 as the latest version of SQLAchemy as they do not support
# Ignore 51668 as the latest version of SQLAchemy and
# Ignore 52355 as the latest version of gitpython as they do not support
# python 3.6 which is still used in production
session.run(
"safety",
Expand All @@ -87,6 +88,8 @@ def safety(session):
"51457",
"--ignore",
"51668",
"--ignore",
"52322",
)

try:
Expand Down
5 changes: 3 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fe6b137

Please sign in to comment.