Complete the code to mark the test as independent using pytest.
import pytest @pytest.mark.[1] def test_example(): assert 1 + 1 == 2
The correct pytest marker to indicate test independence is independent.
Complete the code to reset the shared resource before each test using a fixture.
import pytest @pytest.fixture(autouse=True) def reset_resource(): global resource resource = [1] resource = 0 def test_increment(): global resource resource += 1 assert resource == 1
Resetting the shared resource to 0 ensures tests start fresh.
Fix the error in the test to avoid dependence on previous test results.
def test_append_item(): items = [] items.append('apple') assert len(items) == [1]
After appending one item, the list length should be 1.
Fill both blanks to create a fixture that provides a fresh list for each test.
import pytest @pytest.fixture def [1](): return [2]
The fixture named fresh_list returns a new empty list using list() each time.
Fill all three blanks to write two independent tests using the fresh_list fixture.
def test_add_item_[1](fresh_list): fresh_list.append('item') assert len(fresh_list) == [2] def test_clear_list_[3](fresh_list): fresh_list.clear() assert len(fresh_list) == 0
The first test is named test_add_item_one and expects length 1. The second test is named test_clear_list_two.
