django-constance/tests/test_test_overrides.py
Vladas Tamoshaitis bd8041c55f
Allow override_config for pytest (#338)
* provides: base override class; unittest and pytest overrides

* raise invalid config error earlier

* update AUTHORS

* avoid AttributeError

* fix comment

* add tests

* fix tests, update docstring

* update docs, improve tests

* fix docs

* fix markdown

* refactor pytest override, use hidden fixture, refactor base and unittest classes

* improve docstring and error

* refactor pytest override to use hooks

* set minimum pytest version

* revert empty lines removal

* introduce pytest test runner for package, refactoring

* WIP

* Finalize tox config, refactor docs, add global fixture

* skip py35

* pytest command: remove unnecessary ignore

* address comments

* Update constance/test/pytest.py

* address comments

* add test for checking nested markers

Co-authored-by: Camilo Nova <camilo.nova@gmail.com>
Co-authored-by: Paweł Zarębski <ppjzarebski@gmail.com>
2020-04-04 11:38:22 -05:00

34 lines
1.3 KiB
Python

from django.test import TestCase
from constance import config
from constance.test import override_config
class OverrideConfigFunctionDecoratorTestCase(TestCase):
"""Test that the override_config decorator works correctly.
Test usage of override_config on test method and as context manager.
"""
def test_default_value_is_true(self):
"""Assert that the default value of config.BOOL_VALUE is True."""
self.assertTrue(config.BOOL_VALUE)
@override_config(BOOL_VALUE=False)
def test_override_config_on_method_changes_config_value(self):
"""Assert that the method decorator changes config.BOOL_VALUE."""
self.assertFalse(config.BOOL_VALUE)
def test_override_config_as_context_manager_changes_config_value(self):
"""Assert that the context manager changes config.BOOL_VALUE."""
with override_config(BOOL_VALUE=False):
self.assertFalse(config.BOOL_VALUE)
self.assertTrue(config.BOOL_VALUE)
@override_config(BOOL_VALUE=False)
class OverrideConfigClassDecoratorTestCase(TestCase):
"""Test that the override_config decorator works on classes."""
def test_override_config_on_class_changes_config_value(self):
"""Asser that the class decorator changes config.BOOL_VALUE."""
self.assertFalse(config.BOOL_VALUE)