Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
182230b
Add optional dependencies
swainn Aug 29, 2025
9ccd701
Tests running (but notall passing) with pytest command
swainn Aug 29, 2025
5b504eb
Add doc strings to fixtures
swainn Aug 29, 2025
dc954bd
Add db mark decorators to tests
swainn Aug 30, 2025
9c71050
Fixed issue with test app not being installed
swainn Aug 31, 2025
d489c8c
Additional db marks
swainn Aug 31, 2025
ce27973
Update workflow to run tests with pytest
swainn Sep 2, 2025
df3a7cc
add django_db mark to setup/teardown
swainn Sep 11, 2025
9596052
Fix job manager tests
swainn Sep 11, 2025
7e090b4
add all .coverage files to .gitignore
swainn Sep 11, 2025
9fc9cc2
More test fixes
swainn Sep 11, 2025
b5e1783
more tests fixed
swainn Sep 11, 2025
d2d386d
pytestify the handoff tests
swainn Sep 11, 2025
7c96e1d
Fix paths tests
swainn Sep 11, 2025
7fcb8aa
pytestify context processor tests
swainn Sep 11, 2025
4a981e5
Additional fixes to tests
swainn Sep 12, 2025
7d2f84c
fix boken handler test
swainn Sep 12, 2025
cafc00c
additional fixes for pytest tests
swainn Sep 12, 2025
38be1a6
Fix gen command tests
swainn Sep 15, 2025
50b4638
Fix issue with test command function being picked up as a test by pytest
swainn Sep 16, 2025
8f257ec
Add tests for missing coverage in quotas
swainn Sep 16, 2025
e09f405
Add additional tests for quotas coverage
swainn Sep 18, 2025
b7b164c
rewrite on quotas admin tests
swainn Sep 26, 2025
89ded2f
autouse setup_resource_quotas fixture
swainn Sep 29, 2025
5cdaf91
Remove datetime.utcnow() deprecated call
swainn Sep 29, 2025
67069df
refactor admin tests to use conftest load_quotas fixture to remove du…
swainn Sep 29, 2025
ffba545
full coverate on tethys_quotas.utilities
swainn Oct 3, 2025
cc01966
Fix test failures and errors after rebase
swainn Oct 18, 2025
e65b358
Add tests for missing coverage in install_commands.py
swainn Oct 18, 2025
790a987
format and lint
swainn Oct 18, 2025
47b1f42
Fix indentation issue - tests failing
swainn Oct 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/tethys.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ jobs:
conda activate tethys
conda list
tethys db start
pip install coveralls reactpy_django
pip install coveralls reactpy_django pytest pytest-django pytest-cov
# Test Tethys
- name: Test Tethys
run: |
. ~/miniconda/etc/profile.d/conda.sh
conda activate tethys
tethys test -c -u -v 2
pytest
# Generate Coverage Report
- name: Generate Coverage Report
if: ${{ matrix.platform == 'ubuntu-latest' && matrix.python-version == '3.10' && matrix.django-version == '4.2' }}
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ docs/_build
tethys_gizmos/static/tethys_gizmos/less/bower_components/*
node_modules
.eggs/
.coverage
.coverage*
tests/coverage_html_report
.*.swp
.DS_Store
Expand Down
23 changes: 22 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ dependencies = [
"django-guardian",
]

[project.optional-dependencies]
test = ["pytest", "pytest-django", "pytest-cov", "requests_mock"]
lint = ["flake8", "black"]

[project.urls]
homepage = "http://tethysplatform.org/"
documentation = "http://docs.tethysplatform.org/en/stable/"
Expand All @@ -60,4 +64,21 @@ local_scheme = "no-local-version"
include = ["tethys_*"]

[tool.setuptools]
package-data = {"*" = ["*"]}
package-data = {"*" = ["*"]}
[tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = "tethys_portal.settings"
addopts = "-s --cov"
testpaths = ["tests/unit_tests/"]

[tool.coverage.run]
omit = [
"docs/*",
"tests/*",
"tethys_portal/_version.py",
"tethys_portal/__init__.py",
"*/migrations/*",
]

[tool.coverage.report]
show_missing = true
skip_covered = true
113 changes: 113 additions & 0 deletions tests/unit_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
from os import devnull
from pathlib import Path
import subprocess
import sys

import pytest

from tethys_apps.models import TethysApp
from tethys_cli.cli_colors import write_warning


def install_prereqs(tests_path):
FNULL = open(devnull, "w")
# Install the Test App if not Installed
try:
import tethysapp.test_app # noqa: F401

if tethysapp.test_app is None:
raise ImportError
except ImportError:
write_warning("Test App not found. Installing.....")
setup_path = Path(tests_path) / "apps" / "tethysapp-test_app"
subprocess.run(
[sys.executable, "-m", "pip", "install", "."],
stdout=FNULL,
stderr=subprocess.STDOUT,
cwd=str(setup_path),
check=True,
)
import tethysapp.test_app # noqa: F401

write_warning("Test App installed successfully.")

# Install the Test Extension if not Installed
try:
import tethysext.test_extension # noqa: F401

if tethysext.test_extension is None:
raise ImportError
except ImportError:
write_warning("Test Extension not found. Installing.....")
setup_path = Path(tests_path) / "extensions" / "tethysext-test_extension"
subprocess.run(
[sys.executable, "-m", "pip", "install", "."],
stdout=FNULL,
stderr=subprocess.STDOUT,
cwd=str(setup_path),
check=True,
)
import tethysext.test_extension # noqa: F401

write_warning("Test Extension installed successfully.")


def remove_prereqs():
FNULL = open(devnull, "w")
# Remove Test App
write_warning("Uninstalling Test App...")
try:
subprocess.run(["tethys", "uninstall", "test_app", "-f"], stdout=FNULL)
write_warning("Test App uninstalled successfully.")
except Exception:
write_warning("Failed to uninstall Test App.")

# Remove Test Extension
write_warning("Uninstalling Test Extension...")
try:
subprocess.run(["tethys", "uninstall", "test_extension", "-f"], stdout=FNULL)
write_warning("Test Extension uninstalled successfully.")
except Exception:
write_warning("Failed to uninstall Test Extension.")


@pytest.fixture(scope="session")
def test_dir():
"""Get path to the 'tests' directory"""
return Path(__file__).parents[1].resolve()


@pytest.fixture(scope="session", autouse=True)
def global_setup_and_teardown(test_dir):
"""Install and remove test apps and extensions before and after tests run."""
print("\n🚀 Starting global test setup...")
install_prereqs(test_dir)
print("✅ Global test setup completed!")
yield
print("\n🧹 Starting global test teardown...")
remove_prereqs()
print("✅ Global test teardown completed!")


def reload_urlconf(urlconf=None):
from django.conf import settings
from django.urls import clear_url_caches
from importlib import reload, import_module

clear_url_caches()
if urlconf is None:
urlconf = settings.ROOT_URLCONF
if urlconf in sys.modules:
reload(sys.modules[urlconf])
else:
import_module(urlconf)


@pytest.fixture(scope="function")
def test_app():
from tethys_apps.harvester import SingletonHarvester

harvester = SingletonHarvester()
harvester.harvest()
reload_urlconf()
return TethysApp.objects.get(package="test_app")
Loading
Loading