Complete the code to write a simple PyTest test function that checks if 2 + 2 equals 4.
def test_addition(): assert 2 + 2 == [1]
The test checks if 2 + 2 equals 4. Using 4 makes the assertion true, so the test passes.
Complete the code to write a PyTest test function that checks if the string 'hello' starts with 'h'.
def test_startswith(): assert 'hello'.[1]('h')
The startswith method checks if the string begins with the given character.
Fix the error in the PyTest test function that checks if the length of list [1, 2, 3] is 3.
def test_list_length(): assert len([1, 2, 3]) == [1]
The list has three elements, so its length is 3. Using 3 makes the assertion true.
Fill both blanks to write a PyTest test that checks if the last character of 'world' is 'd'.
def test_last_char(): assert 'world'[[1]] == [2]
Using index -1 gets the last character of the string. It should equal 'd' for the test to pass.
Fill all three blanks to write a PyTest test that checks if the dictionary {'a': 1, 'b': 2} has key 'a' with value 1.
def test_dict_key_value(): data = [1] assert data[[2]] == [3]
The dictionary has keys 'a' and 'b'. We check if data['a'] equals 1 for the test to pass.