Skip to content

Commit

Permalink
Tests: auto-patch to avoid loading user/site configs
Browse files Browse the repository at this point in the history
  • Loading branch information
MetRonnie committed Jul 2, 2024
1 parent e8bcb50 commit 2661f84
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
16 changes: 6 additions & 10 deletions cylc/uiserver/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Test code and fixtures."""

from getpass import getuser
import inspect
import logging
from pathlib import Path
from shutil import rmtree
from socket import gethostname
from tempfile import TemporaryDirectory
from uuid import uuid4

import pytest
from tornado.web import HTTPError
from traitlets.config import Config
import zmq

Expand All @@ -47,6 +44,7 @@
from cylc.flow.parsec.config import ParsecConfig
from cylc.flow.parsec.validate import cylc_config_validate


class AsyncClientFixture(WorkflowRuntimeClient):
pattern = zmq.REQ
host = ''
Expand Down Expand Up @@ -223,7 +221,7 @@ def mock_authentication_yossarian(monkeypatch):
def jp_server_config(jp_template_dir):
"""Config to turn the CylcUIServer extension on.
Auto-loading, add as an argument in the test function to activate.
Overrides jupyter server fixture of the same name.
"""
config = {
"ServerApp": {
Expand All @@ -235,12 +233,9 @@ def jp_server_config(jp_template_dir):
return config


@pytest.fixture
def patch_conf_files(monkeypatch):
"""Auto-patches the CylcUIServer to prevent it loading config files.
Auto-loading, add as an argument in the test function to activate.
"""
@pytest.fixture(autouse=True)
def patch_conf_files(monkeypatch: pytest.MonkeyPatch):
"""Auto-patches the CylcUIServer to prevent it loading config files."""
monkeypatch.setattr(
'cylc.uiserver.app.CylcUIServer.config_file_paths', []
)
Expand Down Expand Up @@ -364,6 +359,7 @@ def workflow_run_dir(request):
if not request.session.testsfailed:
rmtree(run_dir)


@pytest.fixture
def mock_glbl_cfg(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
"""A Pytest fixture for fiddling global config values.
Expand Down
4 changes: 1 addition & 3 deletions cylc/uiserver/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

@pytest.mark.integration
@pytest.mark.usefixtures("mock_authentication_yossarian")
async def test_cylc_handler(patch_conf_files, jp_fetch):
async def test_cylc_handler(jp_fetch):
"""The Cylc endpoints have been added and work."""
resp = await jp_fetch(
'cylc', 'userprofile', method='GET'
Expand Down Expand Up @@ -60,7 +60,6 @@ async def test_cylc_handler(patch_conf_files, jp_fetch):
]
)
async def test_authorised_and_authenticated(
patch_conf_files,
jp_fetch,
endpoint,
code,
Expand Down Expand Up @@ -95,7 +94,6 @@ async def test_authorised_and_authenticated(
]
)
async def test_unauthorised(
patch_conf_files,
jp_fetch,
endpoint,
code,
Expand Down

0 comments on commit 2661f84

Please sign in to comment.