Best Python code snippet using pytest
test_tmpdir.py
Source:test_tmpdir.py
...292 (adir / "foo.txt").touch()293 self.chmod_r(adir)294 rm_rf(adir)295 assert not adir.is_dir()296 def test_on_rm_rf_error(self, tmp_path: Path) -> None:297 adir = tmp_path / "dir"298 adir.mkdir()299 fn = adir / "foo.txt"300 fn.touch()301 self.chmod_r(fn)302 # unknown exception303 with pytest.warns(pytest.PytestWarning):304 exc_info1 = (None, RuntimeError(), None)305 on_rm_rf_error(os.unlink, str(fn), exc_info1, start_path=tmp_path)306 assert fn.is_file()307 # we ignore FileNotFoundError308 exc_info2 = (None, FileNotFoundError(), None)309 assert not on_rm_rf_error(None, str(fn), exc_info2, start_path=tmp_path)310 # unknown function311 with pytest.warns(312 pytest.PytestWarning,313 match=r"^\(rm_rf\) unknown function None when removing .*foo.txt:\nNone: ",314 ):315 exc_info3 = (None, PermissionError(), None)316 on_rm_rf_error(None, str(fn), exc_info3, start_path=tmp_path)317 assert fn.is_file()318 # ignored function319 with pytest.warns(None) as warninfo:320 exc_info4 = (None, PermissionError(), None)321 on_rm_rf_error(os.open, str(fn), exc_info4, start_path=tmp_path)322 assert fn.is_file()323 assert not [x.message for x in warninfo]324 exc_info5 = (None, PermissionError(), None)325 on_rm_rf_error(os.unlink, str(fn), exc_info5, start_path=tmp_path)326 assert not fn.is_file()327def attempt_symlink_to(path, to_path):328 """Try to make a symlink from "path" to "to_path", skipping in case this platform329 does not support it or we don't have sufficient privileges (common on Windows)."""330 try:331 Path(path).symlink_to(Path(to_path))332 except OSError:333 pytest.skip("could not create symbolic link")334def test_tmpdir_equals_tmp_path(tmpdir, tmp_path):335 assert Path(tmpdir) == tmp_path336def test_basetemp_with_read_only_files(testdir):337 """Integration test for #5524"""338 testdir.makepyfile(339 """...
Looking for an in-depth tutorial around pytest? LambdaTest covers the detailed pytest tutorial that has everything related to the pytest, from setting up the pytest framework to automation testing. Delve deeper into pytest testing by exploring advanced use cases like parallel testing, pytest fixtures, parameterization, executing multiple test cases from a single file, and more.
Skim our below pytest tutorial playlist to get started with automation testing using the pytest framework.
https://www.youtube.com/playlist?list=PLZMWkkQEwOPlcGgDmHl8KkXKeLF83XlrP
Get 100 minutes of automation test minutes FREE!!