From 8b0720f89ff79a28184e4bb55c467c1b21a44676 Mon Sep 17 00:00:00 2001 From: M-A-Demir <119374201+M-A-Demir@users.noreply.github.com> Date: Fri, 20 Sep 2024 16:33:06 +0100 Subject: [PATCH] Fix code block formatting on setup_test_tutorial.md --- docs/setup_test_tutorial.md | 54 ++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/docs/setup_test_tutorial.md b/docs/setup_test_tutorial.md index f8e97d3..690b26e 100644 --- a/docs/setup_test_tutorial.md +++ b/docs/setup_test_tutorial.md @@ -21,16 +21,16 @@ def pytest_generate_tests(metafunc): Then, we store the name of the test class and test function, initialise the asyncio event loop, and the appropriate test object: ~~~ def pytest_generate_tests(metafunc): - class_name = metafunc.cls.__name__ - test_name = metafunc.function.__name__ - loop = asyncio.get_event_loop() - RWTest = ReadWriteTest(configFile=ConfigReadWrite.yaml) + class_name = metafunc.cls.__name__ + test_name = metafunc.function.__name__ + loop = asyncio.get_event_loop() + RWTest = ReadWriteTest(configFile=ConfigReadWrite.yaml) ~~~ Now, add an ‘if’ statement that ensures that the setup code runs before the test function is called. In this example, we will have a test class called ‘Test_Copy’, and the test function will be called ‘test_copy’: ~~~ - if class_name == "Test_Copy": - if test_name == "test_copy": + if class_name == "Test_Copy": + if test_name == "test_copy": ~~~ Time to write the setup code – Under ```if test_name == "test_copy":```, let’s store the test file name as a variable, use the genScenarios method to copy that file to the endpoints, and store the outputs: @@ -82,21 +82,21 @@ import asyncio Next, define the test class and within it, the test function. ~~~ class Test_Copy: - def test_copy(self): + def test_copy(self): ~~~ When parametrizing the test, we passed the arguments: ```metafunc.parametrize("cmdOut, destsums, destderrs", testCases, ids=outputs[‘IDs’])``` Pass these same arguments to the test_copy function: ~~~ - def test_copy(self, cmdOut, destsum, destderr): + def test_copy(self, cmdOut, destsum, destderr): (returncode, stdout, stderr), srcsum = cmdOut ~~~ We also unpacked the ```cmdOut``` argument to get the individual ```returncode, stdout, stderr``` and ```srcsum``` values for the scenario. Now we can add the assert statements. For the copy test to pass, the copy command’s returncode should == 0, and the srcsum and destsum should match: ~~~ - assert returncode == 0, f"Upload Failed: {stdout}, {stderr}" + assert returncode == 0, f"Upload Failed: {stdout}, {stderr}" assert srcsum == destsum, f"Stat failed: Source: {srcsum}, Dest: {destsum} Error: {destderr}" ~~~ @@ -111,29 +111,29 @@ import pytest import asyncio class Test_Copy: - def test_copy(self, cmdOut, destsum, destderr): + def test_copy(self, cmdOut, destsum, destderr): (returncode, stdout, stderr), srcsum = cmdOut - assert returncode == 0, f"Upload Failed: {stdout}, {stderr}" + assert returncode == 0, f"Upload Failed: {stdout}, {stderr}" assert srcsum == destsum, f"Stat failed: Source: {srcsum}, Dest: {destsum} Error: {destderr}" ```Test setup:``` def pytest_generate_tests(metafunc): - class_name = metafunc.cls.__name__ - test_name = metafunc.function.__name__ - loop = asyncio.get_event_loop() - RWTest = ReadWriteTest(configFile=ConfigReadWrite.yaml) - if class_name == "Test_Copy": - if test_name == "test_copy": - FILENAME = 'tst.txt' - outputs = loop.run_until_complete(RWTest.genScenarios('copy', sourcePath=f'../TestData/{FILENAME}', - xrdArgs='--force', gfalArgs='--force')) - - destsums = loop.run_until_complete(RWTest.genScenarios('checksum', destinBaseNm=FILENAME)) - - testCases = zip(zip(outputs['cmdOuts'], outputs['srcsums']), - destsums['destsums'], destsums['cmdOuts']) - - metafunc.parametrize("cmdOut, destsums, destderrs", testCases, ids=outputs[‘IDs’]) + class_name = metafunc.cls.__name__ + test_name = metafunc.function.__name__ + loop = asyncio.get_event_loop() + RWTest = ReadWriteTest(configFile=ConfigReadWrite.yaml) + if class_name == "Test_Copy": + if test_name == "test_copy": + FILENAME = 'tst.txt' + outputs = loop.run_until_complete(RWTest.genScenarios('copy', sourcePath=f'../TestData/{FILENAME}', + xrdArgs='--force', gfalArgs='--force')) + + destsums = loop.run_until_complete(RWTest.genScenarios('checksum', destinBaseNm=FILENAME)) + + testCases = zip(zip(outputs['cmdOuts'], outputs['srcsums']), + destsums['destsums'], destsums['cmdOuts']) + + metafunc.parametrize("cmdOut, destsums, destderrs", testCases, ids=outputs[‘IDs’]) ~~~ The test can now be run in the command line: