Skip to content

Commit

Permalink
Test improvements - part 1 (conda-incubator#919)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
soapy1 and pre-commit-ci[bot] authored Oct 25, 2024
1 parent 5ae9e12 commit ed9b597
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 24 deletions.
27 changes: 27 additions & 0 deletions conda-store-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,30 @@

A multi-tenant server for managing conda environments.
See the [documentation](https://conda.store/) for more information.

## Running tests

### Run tests with pytest
```
# ignoring integration tests
$ python -m pytest -m "not extended_prefix and not user_journey" tests/
# ignoring long running tests
$ python -m pytest -m "not extended_prefix and not user_journey and not long_running_test" tests/
```

### Run tests with code coverage
Ensure you have pytest-cov install
```
$ pip install pytest-cov
```

Run tests
```
$ python -m pytest -m "not extended_prefix and not user_journey" --cov=conda_store_server tests/
```

Check coverage report
```
$ coverage report
```
2 changes: 2 additions & 0 deletions conda-store-server/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,6 @@ markers = [
"playwright: mark a test as a playwright test",
"integration: mark a test as an integration test",
"user_journey: mark a test as a user journey test",
"extended_prefix: mark a test as for windows extended_prefix",
"long_running_test: mark a test that takes a long time to run",
]
3 changes: 3 additions & 0 deletions conda-store-server/tests/_internal/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (c) conda-store development team. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
3 changes: 3 additions & 0 deletions conda-store-server/tests/_internal/action/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (c) conda-store development team. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def test_function(context):
@mock.patch.object(generate_lockfile, "yaml", wraps=yaml)
@mock.patch("conda_store_server._internal.action.generate_lockfile.logged_command")
@mock.patch("conda_store_server._internal.action.generate_lockfile.run_lock")
@pytest.mark.long_running_test
def test_solve_lockfile(
mock_run_lock,
mock_logged_command,
Expand Down Expand Up @@ -144,6 +145,7 @@ def test_solve_lockfile_valid_conda_flags(conda_store, simple_specification):


# Checks that conda_flags is used by conda-lock
@pytest.mark.long_running_test
def test_solve_lockfile_invalid_conda_flags(conda_store, simple_specification):
with pytest.raises(
Exception, match=(r"Command.*--this-is-invalid.*returned non-zero exit status")
Expand All @@ -163,6 +165,7 @@ def test_solve_lockfile_invalid_conda_flags(conda_store, simple_specification):
"simple_specification_with_pip",
],
)
@pytest.mark.long_running_test
def test_solve_lockfile_multiple_platforms(conda_store, specification, request):
specification = request.getfixturevalue(specification)
context = action.action_solve_lockfile(
Expand Down Expand Up @@ -260,6 +263,7 @@ def test_fetch_and_extract_conda_packages(tmp_path, simple_conda_lock):
assert context.stdout.getvalue()


@pytest.mark.long_running_test
def test_install_specification(tmp_path, conda_store, simple_specification):
conda_prefix = tmp_path / "test"

Expand All @@ -282,6 +286,7 @@ def test_install_lockfile(tmp_path, conda_store, simple_conda_lock):
assert conda_utils.is_conda_prefix(conda_prefix)


@pytest.mark.long_running_test
def test_generate_conda_export(conda_store, conda_prefix):
context = action.action_generate_conda_export(
conda_command=conda_store.conda_command, conda_prefix=conda_prefix
Expand All @@ -293,6 +298,7 @@ def test_generate_conda_export(conda_store, conda_prefix):
schema.CondaSpecification.parse_obj(context.result)


@pytest.mark.long_running_test
def test_generate_conda_pack(tmp_path, conda_prefix):
output_filename = tmp_path / "environment.tar.gz"

Expand All @@ -310,6 +316,7 @@ def test_generate_conda_pack(tmp_path, conda_prefix):
"https://github.com/conda-incubator/conda-store/issues/666"
)
)
@pytest.mark.long_running_test
def test_generate_conda_docker(conda_store, conda_prefix):
action.action_generate_conda_docker(
conda_prefix=conda_prefix,
Expand Down Expand Up @@ -376,6 +383,7 @@ def test_get_conda_prefix_stats(tmp_path, conda_store, simple_conda_lock):
assert context.result["disk_usage"] > 0


@pytest.mark.long_running_test
def test_add_conda_prefix_packages(db, conda_store, simple_specification, conda_prefix):
build_id = conda_store.register_environment(
db, specification=simple_specification, namespace="pytest"
Expand All @@ -391,6 +399,7 @@ def test_add_conda_prefix_packages(db, conda_store, simple_specification, conda_
assert len(build.package_builds) > 0


@pytest.mark.long_running_test
def test_add_lockfile_packages(
db,
conda_store,
Expand Down Expand Up @@ -424,6 +433,7 @@ def test_add_lockfile_packages(
(True, 1), # build_key_version doesn't matter because there's no lockfile
],
)
@pytest.mark.long_running_test
def test_api_get_build_lockfile(
request,
conda_store,
Expand Down Expand Up @@ -540,6 +550,7 @@ def lockfile_url(build_key):
assert res.status_code == 307


@pytest.mark.long_running_test
def test_api_get_build_installer(
request, conda_store, db, simple_specification_with_pip, conda_prefix
):
Expand Down
3 changes: 3 additions & 0 deletions conda-store-server/tests/_internal/server/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (c) conda-store development team. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
3 changes: 3 additions & 0 deletions conda-store-server/tests/_internal/server/views/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (c) conda-store development team. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
Original file line number Diff line number Diff line change
Expand Up @@ -876,30 +876,6 @@ def test_delete_build_auth(testclient, seed_conda_store, authenticate, celery_wo
# assert r.status == schema.APIStatus.ERROR


def test_prometheus_metrics(testclient):
response = testclient.get("metrics")
d = {
line.split()[0]: line.split()[1]
for line in response.content.decode("utf-8").split("\n")
}
assert {
"conda_store_disk_free",
"conda_store_disk_total",
"conda_store_disk_usage",
} <= d.keys()


def test_celery_stats(testclient, celery_worker):
response = testclient.get("celery")
assert response.json().keys() == {
"active_tasks",
"availability",
"registered_tasks",
"scheduled_tasks",
"stats",
}


@pytest.mark.parametrize(
"route",
[
Expand Down
27 changes: 27 additions & 0 deletions conda-store-server/tests/_internal/server/views/test_metrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (c) conda-store development team. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.


def test_prometheus_metrics(testclient):
response = testclient.get("metrics")
d = {
line.split()[0]: line.split()[1]
for line in response.content.decode("utf-8").split("\n")
}
assert {
"conda_store_disk_free",
"conda_store_disk_total",
"conda_store_disk_usage",
} <= d.keys()


def test_celery_stats(testclient, celery_worker):
response = testclient.get("celery")
assert response.json().keys() == {
"active_tasks",
"availability",
"registered_tasks",
"scheduled_tasks",
"stats",
}
File renamed without changes.
3 changes: 3 additions & 0 deletions conda-store-server/tests/server/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (c) conda-store development team. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

import sys

import pytest

from celery.result import AsyncResult

from conda_store_server import api
from conda_store_server._internal import action, conda_utils, schema


@pytest.mark.long_running_test
def test_conda_store_app_register_solve(
db, conda_store, simple_specification, simple_conda_lock, celery_worker
):
Expand Down Expand Up @@ -41,6 +44,7 @@ def test_conda_store_app_register_solve(
assert len(solve.package_builds) > 0


@pytest.mark.long_running_test
def test_conda_store_register_environment_workflow(
db, simple_specification, conda_store, celery_worker
):
Expand Down

0 comments on commit ed9b597

Please sign in to comment.