Beispiel #1
0
def test_get_calling_module():
    # Reference to this very module
    this_module = getmodule(test_get_calling_module)

    # Once removed is the `pytest` module calling this function
    pytest_module = get_calling_module(1)
    assert pytest_module != this_module
    assert "pytest" in pytest_module.__name__

    # Test functions
    def dummy_secondary_method():
        return get_calling_module(2), get_calling_module(3)

    def dummy_method():
        return (*dummy_secondary_method(), get_calling_module(1), get_calling_module(2))

    # Unpack results from the function chain
    sec_mod, sec_pytest_mod, dummy_mod, pytest_mod = dummy_method()

    assert sec_mod == this_module
    assert "pytest" in sec_pytest_mod.__name__
    assert dummy_mod == this_module
    assert "pytest" in pytest_mod.__name__

    # Raise an `IndexError` when attempting to access too many frames removed
    with pytest.raises(IndexError):
        assert get_calling_module(100)
Beispiel #2
0
 def dummy_method():
     return (*dummy_secondary_method(), get_calling_module(1), get_calling_module(2))
Beispiel #3
0
 def dummy_secondary_method():
     return get_calling_module(2), get_calling_module(3)