How to use symlink_or_skip method in Pytest

Best Python code snippet using pytest

test_conftest.py

Source:test_conftest.py Github

copy

Full Screen

...173 # /symlinktests -> /real/app/tests (running at symlinktests should fail)174 # /symlink -> /real (running at /symlink should work)175 real = testdir.tmpdir.mkdir("real")176 realtests = real.mkdir("app").mkdir("tests")177 symlink_or_skip(realtests, testdir.tmpdir.join("symlinktests"))178 symlink_or_skip(real, testdir.tmpdir.join("symlink"))179 testdir.makepyfile(180 **{181 "real/app/tests/test_foo.py": "def test1(fixture): pass",182 "real/conftest.py": textwrap.dedent(183 """184 import pytest185 print("conftest_loaded")186 @pytest.fixture187 def fixture():188 print("fixture_used")189 """190 ),191 }192 )193 # Should fail because conftest cannot be found from the link structure.194 result = testdir.runpytest("-vs", "symlinktests")195 result.stdout.fnmatch_lines(["*fixture 'fixture' not found*"])196 assert result.ret == ExitCode.TESTS_FAILED197 # Should not cause "ValueError: Plugin already registered" (#4174).198 result = testdir.runpytest("-vs", "symlink")199 assert result.ret == ExitCode.OK200def test_conftest_symlink_files(testdir):201 """Symlinked conftest.py are found when pytest is executed in a directory with symlinked202 files."""203 real = testdir.tmpdir.mkdir("real")204 source = {205 "app/test_foo.py": "def test1(fixture): pass",206 "app/__init__.py": "",207 "app/conftest.py": textwrap.dedent(208 """209 import pytest210 print("conftest_loaded")211 @pytest.fixture212 def fixture():213 print("fixture_used")214 """215 ),216 }217 testdir.makepyfile(**{"real/%s" % k: v for k, v in source.items()})218 # Create a build directory that contains symlinks to actual files219 # but doesn't symlink actual directories.220 build = testdir.tmpdir.mkdir("build")221 build.mkdir("app")222 for f in source:223 symlink_or_skip(real.join(f), build.join(f))224 build.chdir()225 result = testdir.runpytest("-vs", "app/test_foo.py")226 result.stdout.fnmatch_lines(["*conftest_loaded*", "PASSED"])227 assert result.ret == ExitCode.OK228@pytest.mark.skipif(229 os.path.normcase("x") != os.path.normcase("X"),230 reason="only relevant for case insensitive file systems",231)232def test_conftest_badcase(testdir):233 """Check conftest.py loading when directory casing is wrong (#5792)."""234 testdir.tmpdir.mkdir("JenkinsRoot").mkdir("test")235 source = {"setup.py": "", "test/__init__.py": "", "test/conftest.py": ""}236 testdir.makepyfile(**{"JenkinsRoot/%s" % k: v for k, v in source.items()})237 testdir.tmpdir.join("jenkinsroot/test").chdir()...

Full Screen

Full Screen

Pytest Tutorial

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.

Chapters

  1. What is pytest
  2. Pytest installation: Want to start pytest from scratch? See how to install and configure pytest for Python automation testing.
  3. Run first test with pytest framework: Follow this step-by-step tutorial to write and run your first pytest script.
  4. Parallel testing with pytest: A hands-on guide to parallel testing with pytest to improve the scalability of your test automation.
  5. Generate pytest reports: Reports make it easier to understand the results of pytest-based test runs. Learn how to generate pytest reports.
  6. Pytest Parameterized tests: Create and run your pytest scripts while avoiding code duplication and increasing test coverage with parameterization.
  7. Pytest Fixtures: Check out how to implement pytest fixtures for your end-to-end testing needs.
  8. Execute Multiple Test Cases: Explore different scenarios for running multiple test cases in pytest from a single file.
  9. Stop Test Suite after N Test Failures: See how to stop your test suite after n test failures in pytest using the @pytest.mark.incremental decorator and maxfail command-line option.

YouTube

Skim our below pytest tutorial playlist to get started with automation testing using the pytest framework.

https://www.youtube.com/playlist?list=PLZMWkkQEwOPlcGgDmHl8KkXKeLF83XlrP

Run Pytest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful