From 7504aead864370e35ffd85213281e8379bc429b1 Mon Sep 17 00:00:00 2001 From: Norwid Behrnd Date: Tue, 28 Sep 2021 14:26:46 +0000 Subject: [PATCH] Continue on all tests, even if one fails. The retraction of the -x parameter for pytest ensures that all test functions defined are actually used. Previously, testing stopped immediately, conveying an incomplete picture of date2name's work implemented. Testing the retraction option -r, there is no need for a delay between the indivdual options, either. --- Makefile | 10 ++++++---- test_date2name.py | 16 ++++++---------- test_generator.org | 28 +++++++++++++--------------- 3 files changed, 25 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index c197b8f..e6588ff 100755 --- a/Makefile +++ b/Makefile @@ -13,8 +13,10 @@ # chmod +x * # make ./Makefile # -# to run the tests. The test sequence either stops at the first test -# failing, or after completion. +# to run the tests. The test sequence will explicitly report if a test +# was passed successfully, or failed. If you want to script to stop on +# the first encounter of a test failed, add option -x on the commands +# set below -# pytest -xv test_date2name.py # only pytest for Python 3 is present -pytest-3 -xv test_date2name.py # pytest if Python 2 and Python 3 coexist +# pytest -v test_date2name.py # only pytest for Python 3 is present +pytest-3 -v test_date2name.py # pytest if Python 2 and Python 3 coexist diff --git a/test_date2name.py b/test_date2name.py index 859d762..b42bdda 100644 --- a/test_date2name.py +++ b/test_date2name.py @@ -4,7 +4,7 @@ # author: nbehrnd@yahoo.com # license: GPL v3, 2021. # date: 2021-08-30 (YYYY-MM-DD) -# edit: 2021-09-17 (YYYY-MM-DD) +# edit: 2021-09-28 (YYYY-MM-DD) # """Test pad for functions by date2name with pytest. @@ -225,8 +225,8 @@ def test_short_pattern_YYMMDD(arg1): assert os.path.isfile(new) os.remove(new) -import time, os, sys -@pytest.mark.parametrize("arg1", ["default", "short", "compact", "month", "withtime"]) +@pytest.mark.parametrize("arg1", ["default", "short", "compact", + "month", "withtime"]) @pytest.mark.parametrize("arg2", ["-r", "--remove"]) def test_remove_stamp(arg1, arg2): """Check the retraction of the leading time stamp.""" @@ -242,15 +242,11 @@ def test_remove_stamp(arg1, arg2): TFILE = "_".join([prepend, BASIS]) with open(TFILE, mode = "w") as newfile: newfile.write("This is a test file.") - time.sleep(2) test = getoutput(f"python3 {PROGRAM} {TFILE} {arg2}") - time.sleep(2) + assert os.path.isfile(TFILE) is False # absence of stamped file assert os.path.isfile(BASIS) # presence unstamped file - try: - os.remove("test.txt") - except OSError: - print("Running remove test, file 'test.txt' was not erased.") - sys.exit() + os.remove("test.txt") # succesful space cleaning for next test + assert os.path.isfile("test.txt") is False diff --git a/test_generator.org b/test_generator.org index d9044c9..aab5920 100755 --- a/test_generator.org +++ b/test_generator.org @@ -72,11 +72,13 @@ # chmod +x * # make ./Makefile # - # to run the tests. The test sequence either stops at the first test - # failing, or after completion. - - # pytest -xv test_date2name.py # only pytest for Python 3 is present - pytest-3 -xv test_date2name.py # pytest if Python 2 and Python 3 coexist + # to run the tests. The test sequence will explicitly report if a test + # was passed successfully, or failed. If you want to script to stop on + # the first encounter of a test failed, add option -x on the commands + # set below + + # pytest -v test_date2name.py # only pytest for Python 3 is present + pytest-3 -v test_date2name.py # pytest if Python 2 and Python 3 coexist #+end_src @@ -90,7 +92,7 @@ # author: nbehrnd@yahoo.com # license: GPL v3, 2021. # date: 2021-08-30 (YYYY-MM-DD) - # edit: 2021-09-17 (YYYY-MM-DD) + # edit: 2021-09-28 (YYYY-MM-DD) # """Test pad for functions by date2name with pytest. @@ -363,8 +365,8 @@ successful to retract this stamp. #+begin_src python :tangle test_date2name.py - import time, os, sys - @pytest.mark.parametrize("arg1", ["default", "short", "compact", "month", "withtime"]) + @pytest.mark.parametrize("arg1", ["default", "short", "compact", + "month", "withtime"]) @pytest.mark.parametrize("arg2", ["-r", "--remove"]) def test_remove_stamp(arg1, arg2): """Check the retraction of the leading time stamp.""" @@ -380,16 +382,12 @@ TFILE = "_".join([prepend, BASIS]) with open(TFILE, mode = "w") as newfile: newfile.write("This is a test file.") - time.sleep(2) test = getoutput(f"python3 {PROGRAM} {TFILE} {arg2}") - time.sleep(2) + assert os.path.isfile(TFILE) is False # absence of stamped file assert os.path.isfile(BASIS) # presence unstamped file - try: - os.remove("test.txt") - except OSError: - print("Running remove test, file 'test.txt' was not erased.") - sys.exit() + os.remove("test.txt") # succesful space cleaning for next test + assert os.path.isfile("test.txt") is False #+end_src