-
Notifications
You must be signed in to change notification settings - Fork 0
Implement pytest #39
Comments
To demonstrate the functionality of Pytest, a demonstration script will be created with no connection to current scripts within the webQueue2 to demonstrate basic testing of basic data types including numbers, strings, lists, and dictionaries. |
https://docs.pytest.org/en/stable/getting-started.html#group-multiple-tests-in-a-class |
To run Then Run the command:
|
Pytest: Post Test ReportsThe example code in this guide demonstrates how to output information to a text file every time pytest runs. In this particular example, every time pytest runs, the name of any function that fails is output to a "failures" file in the same directory. Example output of failed functions:
This guide discusses using |
Pytest Post Test Reports: Current ImplementationThe way pytest is configured, as of now, is to output the name of any function that failed during the execution of pytest. To determine if the most recent execution of pytest failed, without looking at the output in the terminal, simply search for the existence of the |
Tests for Monday's demo (for the Queue class):
|
Pytest with Queue ClassThere is now a very basic pytest script within the api folder that demonstrates a very basic method of testing the Queue class for basic assertions. import pytest
from ECNQueue import Queue, Item
testQueue = Queue("ce")
@pytest.mark.name
def test_Name():
assert type(testQueue.name) == str
assert testQueue.name == "ce"
@pytest.mark.Items
def test_Items():
assert type(testQueue.items) == list
assert len(testQueue.items) == 48
def test_Json():
assert type(testQueue.jsonData["name"]) == str
assert testQueue.name == testQueue.jsonData["name"]
assert type(len(testQueue.items)) == int
assert len(testQueue.items) == testQueue.jsonData["length"]
assert testQueue.items[0].jsonData["number"] == "17" This script imports the |
Updates to BackendPytest is explicit in that a specific assertion must be made in pytest to test against possible code. All updates to the backend in general must also be reflected in any pytest scripts, where applicable. For example, the current implementation of the [
{
'name': 'bidc',
'number_of_items': 5
},
{
'name': 'epics',
'number_of_items': 6
}
] Pytest can be as granular or as broad as needed, meaning that pytest could simply check that a list of dictionaries is returned when the A potential problem exists in the upkeep of pytest scripts, in that any backend changes must also be accommodated for within pytest, depending on the extent and specificity of the pytest scripts. If the name of the key needs to be changed in the backend, pytest needs to be updated to reflect that new name. |
Testing Function ExceptionsIt is possible to test if and which exceptions are thrown by a function using the |
Exception HandlingThis should probably be a separate issue, however, there are some functions in the backend that need to incorporate a level of exception handling that is not currently implemented. Specifically, |
Pytest and Backend package requirementsIt might be beneficial if pytest and the backend api were included in the |
|
From this comment:
From this comment:
From this comment:
From this comment:
|
Reply to previous comment:
|
Closing this issue here and reopening on the API GitHub. |
Currently there is no infrastructure to test immediate or regressive changes. pytest is a popular testing suite for Python. It should be investigated for usability. The proof of concept test could be to create tests for the Queue class in the ECNQueue Module.
The text was updated successfully, but these errors were encountered: