From 24dcfec09cd680f356520f4508274dddd9cd669d Mon Sep 17 00:00:00 2001 From: nhertz <nhertz@nrao.edu> Date: Fri, 21 Aug 2020 15:06:46 -0600 Subject: [PATCH] Changed test naming convention. Added custom fixture for initializing Null object. --- .../null/test/{null_test.py => test_null.py} | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) rename apps/cli/executables/null/test/{null_test.py => test_null.py} (65%) diff --git a/apps/cli/executables/null/test/null_test.py b/apps/cli/executables/null/test/test_null.py similarity index 65% rename from apps/cli/executables/null/test/null_test.py rename to apps/cli/executables/null/test/test_null.py index c8da965d0..7dd49717c 100644 --- a/apps/cli/executables/null/test/null_test.py +++ b/apps/cli/executables/null/test/test_null.py @@ -1,37 +1,36 @@ import pytest import argparse -from null.null import Null +# from null.null import Null +from ..src.null.null import Null -parser = argparse.ArgumentParser() - -def test_print_error(caplog): +@pytest.fixture() +def null(): null = Null(argparse.Namespace(), True) + return null + +def test_print_error(null, caplog): null.print_error() assert 'ERROR: This is an error.' in caplog.text -def test_print_greeting(caplog): - null = Null(argparse.Namespace(), True) +def test_print_greeting(null, caplog): null.print_greeting() assert 'Hello, world!' in caplog.text assert 'And goodbye, world...' in caplog.text -def test_exit_with_failure(caplog): - null = Null(argparse.Namespace(), True) +def test_exit_with_failure(null, caplog): with pytest.raises(SystemExit) as e: null.exit_with_failure() assert 'Error purposefully induced. Exiting with status code -1...' in caplog.text assert e.value.code == -1 -def test_exit_randomly(caplog): - null = Null(argparse.Namespace(), True) +def test_exit_randomly(null, caplog): with pytest.raises(SystemExit) as e: null.exit_randomly() assert 'Exiting with status code' in caplog.text assert -50 <= e.value.code <= 50 -def test_take_nap(caplog): - null = Null(argparse.Namespace(), True) +def test_take_nap(null, caplog): null.take_nap() assert 'Going to sleep...' in caplog.text assert 'Waking up.' in caplog.text \ No newline at end of file -- GitLab