[lang-ref] ( file_exists ) ( python )

@pytest.fixture
def pushd(tmp_path):
    old = os.getcwd()
    os.chdir(tmp_path)
    yield
    os.chdir(old)

def test_file_exists():
    # os.path.isfile
    assert os.path.isfile('/etc/hosts')    is True
    assert os.path.isfile('/no/such/file') is False
def test_file_exists_alternative():
    # pathlib.Path.is_file()
    assert Path('/etc/hosts').is_file()    is True
    assert Path('/no/such/file').is_file() is False