Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make PanBase hermetic across tests by clearing _config each time #249

Merged
merged 2 commits into from
Dec 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions pocs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
_config = None


def reset_global_config():
"""Reset the global _config to None.

Globals such as _config make tests non-hermetic. Enable conftest.py to clear _config
in an explicit fashion.
"""
global _config
_config = None


class PanBase(object):

""" Base class for other classes within the PANOPTES ecosystem
Expand Down
18 changes: 14 additions & 4 deletions pocs/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import copy
import os
import pytest

import pocs.base
from pocs import hardware
from pocs.utils.config import load_config
from pocs.utils.database import PanMongo

# Global variable with the default config; we read it once, copy it each time it is needed.
_one_time_config = None


def pytest_addoption(parser):
parser.addoption("--with-hardware", nargs='+', default=[],
Expand Down Expand Up @@ -44,11 +49,16 @@ def pytest_collection_modifyitems(config, items):
item.add_marker(skip)


@pytest.fixture
@pytest.fixture(scope='function')
def config():
config = load_config(ignore_local=True, simulator=['all'])
config['db']['name'] = 'panoptes_testing'
return config
pocs.base.reset_global_config()

global _one_time_config
if not _one_time_config:
_one_time_config = load_config(ignore_local=True, simulator=['all'])
_one_time_config['db']['name'] = 'panoptes_testing'

return copy.deepcopy(_one_time_config)


@pytest.fixture
Expand Down