Skip to content

Commit

Permalink
Make PanBase hermetic across tests by clearing _config each time (#249)
Browse files Browse the repository at this point in the history
* Make PanBase hermetic across tests by clearing _config each time.
  • Loading branch information
jamessynge authored and wtgee committed Dec 25, 2017
1 parent f53c96e commit 37bc82a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
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

0 comments on commit 37bc82a

Please sign in to comment.