Skip to content

Commit

Permalink
Automatically add fixtures as markers (#174)
Browse files Browse the repository at this point in the history
* Automatically add fixtures as markers

* Ignore warning for ignored pytest internal

* Remove explicit markers, as fixtures now serve as markers also
  • Loading branch information
PGijsbers authored Jul 23, 2024
1 parent 5720351 commit b0d24cf
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
docker compose up -d --wait python-api php-api
- run: docker container ls && docker image ls
- run: docker exec python-api python -m pip freeze
- run: docker exec python-api python -m pytest -xv -m "php"
- run: docker exec python-api python -m pytest -xv -m "php_api"
python:
runs-on: ubuntu-latest
steps:
Expand All @@ -38,4 +38,4 @@ jobs:
- run: docker compose up -d --wait database python-api
- run: docker container ls && docker image ls
- run: docker exec python-api python -m pip freeze
- run: docker exec python-api python -m pytest -xv -m "not php"
- run: docker exec python-api python -m pytest -xv -m "not php_api"
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ pythonpath = [
"src"
]
markers = [
"php: tests that compare directly to an old PHP endpoint.",
"slow: test or sets of tests which take more than a few seconds to run.",
# While the `mut`ation marker below is not strictly necessary as every change is
# executed within transaction that is rolled back, it can halt other unit tests which
# whose queries may depend on the execution or rollback of the transaction.
"mut: executes a mutation on the database (in a transaction which is rolled back)",
]
filterwarnings = [
'ignore:A private pytest class or function was used.:DeprecationWarning:tests.conftest:119',
]
9 changes: 9 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
from pathlib import Path
from typing import Any, Iterator, NamedTuple

import _pytest.mark
import httpx
import pytest
from _pytest.config import Config
from _pytest.nodes import Item
from database.setup import expdb_database, user_database
from fastapi.testclient import TestClient
from main import create_api
Expand Down Expand Up @@ -108,3 +111,9 @@ def persisted_flow(flow: Flow, expdb_test: Connection) -> Iterator[Flow]:
parameters={"flow_id": flow.id},
)
expdb_test.commit()


def pytest_collection_modifyitems(config: Config, items: list[Item]) -> None: # noqa: ARG001
for test_item in items:
for fixture in test_item.fixturenames: # type: ignore[attr-defined]
test_item.own_markers.append(_pytest.mark.Mark(fixture, (), {}))
1 change: 0 additions & 1 deletion tests/routers/openml/datasets_list_datasets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ def test_list_data_quality(quality: str, range_: str, count: int, py_api: TestCl
assert len(response.json()) == count


@pytest.mark.php()
@pytest.mark.slow()
@hypothesis.settings(
max_examples=5000,
Expand Down
3 changes: 0 additions & 3 deletions tests/routers/openml/migration/datasets_migration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from tests.conftest import ApiKey


@pytest.mark.php()
@pytest.mark.parametrize(
"dataset_id",
range(1, 132),
Expand Down Expand Up @@ -136,7 +135,6 @@ def test_private_dataset_admin_access(py_api: TestClient) -> None:
# test against cached response


@pytest.mark.php()
@pytest.mark.parametrize(
"dataset_id",
list(range(1, 10)) + [101],
Expand Down Expand Up @@ -188,7 +186,6 @@ def test_dataset_tag_response_is_identical(
assert original == new


@pytest.mark.php()
@pytest.mark.parametrize(
"data_id",
list(range(1, 130)),
Expand Down
3 changes: 0 additions & 3 deletions tests/routers/openml/migration/evaluations_migration_test.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
from typing import Any

import httpx
import pytest
from starlette.testclient import TestClient


@pytest.mark.php()
def test_evaluationmeasure_list(py_api: TestClient, php_api: httpx.Client) -> None:
new = py_api.get("/evaluationmeasure/list")
original = php_api.get("/evaluationmeasure/list")
assert new.status_code == original.status_code
assert new.json() == original.json()["evaluation_measures"]["measures"]["measure"]


@pytest.mark.php()
def test_estimation_procedure_list(py_api: TestClient, php_api: httpx.Client) -> None:
new = py_api.get("/estimationprocedure/list")
original = php_api.get("/estimationprocedure/list")
Expand Down
3 changes: 0 additions & 3 deletions tests/routers/openml/migration/flows_migration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@


@pytest.mark.mut()
@pytest.mark.php()
def test_flow_exists_not(
py_api: TestClient,
php_api: TestClient,
Expand All @@ -32,7 +31,6 @@ def test_flow_exists_not(


@pytest.mark.mut()
@pytest.mark.php()
def test_flow_exists(
persisted_flow: Flow,
py_api: TestClient,
Expand All @@ -49,7 +47,6 @@ def test_flow_exists(
assert py_response.json() == {"flow_id": persisted_flow.id}


@pytest.mark.php()
@pytest.mark.parametrize(
"flow_id",
range(1, 16),
Expand Down
2 changes: 0 additions & 2 deletions tests/routers/openml/migration/studies_migration_test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import deepdiff
import httpx
import pytest
from core.conversions import nested_num_to_str, nested_remove_nones
from starlette.testclient import TestClient


@pytest.mark.php()
def test_get_study_equal(py_api: TestClient, php_api: httpx.Client) -> None:
new = py_api.get("/studies/1")
old = php_api.get("/study/1")
Expand Down
1 change: 0 additions & 1 deletion tests/routers/openml/migration/tasks_migration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from starlette.testclient import TestClient


@pytest.mark.php()
@pytest.mark.parametrize(
"task_id",
range(1, 1306),
Expand Down
3 changes: 0 additions & 3 deletions tests/routers/openml/qualities_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def _remove_quality_from_database(quality_name: str, expdb_test: Connection) ->
)


@pytest.mark.php()
def test_list_qualities_identical(py_api: TestClient, php_api: httpx.Client) -> None:
original = php_api.get("/data/qualities/list")
new = py_api.get("/datasets/qualities/list")
Expand Down Expand Up @@ -279,7 +278,6 @@ def test_get_quality(py_api: TestClient) -> None:
assert not difference


@pytest.mark.php()
@pytest.mark.parametrize(
"data_id",
list(set(range(1, 132)) - {55, 56, 59, 116, 130}),
Expand All @@ -299,7 +297,6 @@ def test_get_quality_identical(data_id: int, py_api: TestClient, php_api: httpx.
assert python_response.json() == expected


@pytest.mark.php()
@pytest.mark.parametrize(
"data_id",
[55, 56, 59, 116, 130, 132],
Expand Down
2 changes: 0 additions & 2 deletions tests/routers/openml/task_type_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
from starlette.testclient import TestClient


@pytest.mark.php()
def test_list_task_type(py_api: TestClient, php_api: httpx.Client) -> None:
response = py_api.get("/tasktype/list")
original = php_api.get("/tasktype/list")
assert response.status_code == original.status_code
assert response.json() == original.json()


@pytest.mark.php()
@pytest.mark.parametrize(
"ttype_id",
list(range(1, 12)),
Expand Down

0 comments on commit b0d24cf

Please sign in to comment.