From d9a3496de856df0852b3125aca7cfebedcb880ea Mon Sep 17 00:00:00 2001 From: Emily Date: Sun, 28 Jul 2024 18:50:05 +0100 Subject: [PATCH] Migrate test fixtures to pytest --- tests/core/test_context.py | 10 ++-------- tests/core/test_variable.py | 9 ++------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/tests/core/test_context.py b/tests/core/test_context.py index a963613..b9a6ac4 100644 --- a/tests/core/test_context.py +++ b/tests/core/test_context.py @@ -5,15 +5,14 @@ from gixy.core.variable import Variable from gixy.core.regexp import Regexp -def setup(): +def setup_function(): assert len(CONTEXTS) == 0 -def tear_down(): +def teardown_function(): purge_context() -@with_setup(setup, tear_down) def test_push_pop_context(): root_a = Root() push_context(root_a) @@ -30,7 +29,6 @@ def test_push_pop_context(): assert poped.block == root_a -@with_setup(setup, tear_down) def test_push_get_purge_context(): root = Root() push_context(root) @@ -45,7 +43,6 @@ def test_push_get_purge_context(): assert len(CONTEXTS) == 0 -@with_setup(setup, tear_down) def test_add_variables(): context = push_context(Root()) assert len(context.variables['index']) == 0 @@ -68,7 +65,6 @@ def test_add_variables(): assert context.variables['name']['some'] == some_var -@with_setup(setup, tear_down) def test_get_variables(): context = push_context(Root()) assert len(context.variables['index']) == 0 @@ -91,7 +87,6 @@ def test_get_variables(): assert context.get_var('args') -@with_setup(setup, tear_down) def test_context_depend_variables(): push_context(Root()) assert len(get_context().variables['index']) == 0 @@ -124,7 +119,6 @@ def test_context_depend_variables(): assert get_context().get_var(1).value == 'one' -@with_setup(setup, tear_down) def test_push_failed_with_regexp_py35_gixy_10(): push_context(Root()) assert len(get_context().variables['index']) == 0 diff --git a/tests/core/test_variable.py b/tests/core/test_variable.py index 47a8451..22167f4 100644 --- a/tests/core/test_variable.py +++ b/tests/core/test_variable.py @@ -4,15 +4,14 @@ from gixy.directives.block import Root from gixy.core.regexp import Regexp from gixy.core.variable import Variable -def setup(): +def setup_function(): push_context(Root()) -def tear_down(): +def teardown_function(): purge_context() -@with_setup(setup, tear_down) def test_literal(): var = Variable(name='simple', value='$uri', have_script=False) assert not var.depends @@ -28,7 +27,6 @@ def test_literal(): assert not var.must_startswith('u') -@with_setup(setup, tear_down) def test_regexp(): var = Variable(name='simple', value=Regexp('^/.*')) assert not var.depends @@ -44,7 +42,6 @@ def test_regexp(): assert not var.must_startswith('a') -@with_setup(setup, tear_down) def test_script(): get_context().add_var('foo', Variable(name='foo', value=Regexp('.*'))) var = Variable(name='simple', value='/$foo') @@ -62,7 +59,6 @@ def test_script(): assert not var.must_startswith('a') -@with_setup(setup, tear_down) def test_regexp_boundary(): var = Variable(name='simple', value=Regexp('.*'), boundary=Regexp('/[a-z]', strict=True)) assert not var.depends @@ -80,7 +76,6 @@ def test_regexp_boundary(): assert not var.must_startswith('a') -@with_setup(setup, tear_down) def test_script_boundary(): get_context().add_var('foo', Variable(name='foo', value=Regexp('.*'), boundary=Regexp('[a-z]', strict=True))) var = Variable(name='simple', value='/$foo', boundary=Regexp('[/a-z0-9]', strict=True))