Testing Depth First Search Using Pytest
Three observations:

There are two many assert statements in a single test function. Ideally each function should only test one thing. That way when the test fails you know exactly what is wrong.
Instead of initializing test data in the test function, you can write fixtures. Each fixture can be used in multiple test functions.
You don't need to assert 'KeyError' in str(excinfo.type) since you already has with pytest.raises(KeyError).