How to use pytest_addoption method in Playwright Python

Best Python code snippet using playwright-python

test_config.py

Source:test_config.py Github

copy

Full Screen

...76 config = testdir.parseconfig()77 pytest.raises(AssertionError, lambda: config.parse([]))78 def test_explicitly_specified_config_file_is_loaded(self, testdir):79 testdir.makeconftest("""80 def pytest_addoption(parser):81 parser.addini("custom", "")82 """)83 testdir.makeini("""84 [pytest]85 custom = 086 """)87 testdir.makefile(".cfg", custom = """88 [pytest]89 custom = 190 """)91 config = testdir.parseconfig("-c", "custom.cfg")92 assert config.getini("custom") == "1"93class TestConfigAPI:94 def test_config_trace(self, testdir):95 config = testdir.parseconfig()96 l = []97 config.trace.root.setwriter(l.append)98 config.trace("hello")99 assert len(l) == 1100 assert l[0] == "hello [config]\n"101 def test_config_getoption(self, testdir):102 testdir.makeconftest("""103 def pytest_addoption(parser):104 parser.addoption("--hello", "-X", dest="hello")105 """)106 config = testdir.parseconfig("--hello=this")107 for x in ("hello", "--hello", "-X"):108 assert config.getoption(x) == "this"109 pytest.raises(ValueError, "config.getoption('qweqwe')")110 @pytest.mark.skipif('sys.version_info[:2] not in [(2, 6), (2, 7)]')111 def test_config_getoption_unicode(self, testdir):112 testdir.makeconftest("""113 from __future__ import unicode_literals114 def pytest_addoption(parser):115 parser.addoption('--hello', type='string')116 """)117 config = testdir.parseconfig('--hello=this')118 assert config.getoption('hello') == 'this'119 def test_config_getvalueorskip(self, testdir):120 config = testdir.parseconfig()121 pytest.raises(pytest.skip.Exception,122 "config.getvalueorskip('hello')")123 verbose = config.getvalueorskip("verbose")124 assert verbose == config.option.verbose125 def test_config_getvalueorskip_None(self, testdir):126 testdir.makeconftest("""127 def pytest_addoption(parser):128 parser.addoption("--hello")129 """)130 config = testdir.parseconfig()131 with pytest.raises(pytest.skip.Exception):132 config.getvalueorskip('hello')133 def test_getoption(self, testdir):134 config = testdir.parseconfig()135 with pytest.raises(ValueError):136 config.getvalue('x')137 assert config.getoption("x", 1) == 1138 def test_getconftest_pathlist(self, testdir, tmpdir):139 somepath = tmpdir.join("x", "y", "z")140 p = tmpdir.join("conftest.py")141 p.write("pathlist = ['.', %r]" % str(somepath))142 config = testdir.parseconfigure(p)143 assert config._getconftest_pathlist('notexist', path=tmpdir) is None144 pl = config._getconftest_pathlist('pathlist', path=tmpdir)145 print(pl)146 assert len(pl) == 2147 assert pl[0] == tmpdir148 assert pl[1] == somepath149 def test_addini(self, testdir):150 testdir.makeconftest("""151 def pytest_addoption(parser):152 parser.addini("myname", "my new ini value")153 """)154 testdir.makeini("""155 [pytest]156 myname=hello157 """)158 config = testdir.parseconfig()159 val = config.getini("myname")160 assert val == "hello"161 pytest.raises(ValueError, config.getini, 'other')162 def test_addini_pathlist(self, testdir):163 testdir.makeconftest("""164 def pytest_addoption(parser):165 parser.addini("paths", "my new ini value", type="pathlist")166 parser.addini("abc", "abc value")167 """)168 p = testdir.makeini("""169 [pytest]170 paths=hello world/sub.py171 """)172 config = testdir.parseconfig()173 l = config.getini("paths")174 assert len(l) == 2175 assert l[0] == p.dirpath('hello')176 assert l[1] == p.dirpath('world/sub.py')177 pytest.raises(ValueError, config.getini, 'other')178 def test_addini_args(self, testdir):179 testdir.makeconftest("""180 def pytest_addoption(parser):181 parser.addini("args", "new args", type="args")182 parser.addini("a2", "", "args", default="1 2 3".split())183 """)184 testdir.makeini("""185 [pytest]186 args=123 "123 hello" "this"187 """)188 config = testdir.parseconfig()189 l = config.getini("args")190 assert len(l) == 3191 assert l == ["123", "123 hello", "this"]192 l = config.getini("a2")193 assert l == list("123")194 def test_addini_linelist(self, testdir):195 testdir.makeconftest("""196 def pytest_addoption(parser):197 parser.addini("xy", "", type="linelist")198 parser.addini("a2", "", "linelist")199 """)200 testdir.makeini("""201 [pytest]202 xy= 123 345203 second line204 """)205 config = testdir.parseconfig()206 l = config.getini("xy")207 assert len(l) == 2208 assert l == ["123 345", "second line"]209 l = config.getini("a2")210 assert l == []211 @pytest.mark.parametrize('str_val, bool_val',212 [('True', True), ('no', False), ('no-ini', True)])213 def test_addini_bool(self, testdir, str_val, bool_val):214 testdir.makeconftest("""215 def pytest_addoption(parser):216 parser.addini("strip", "", type="bool", default=True)217 """)218 if str_val != 'no-ini':219 testdir.makeini("""220 [pytest]221 strip=%s222 """ % str_val)223 config = testdir.parseconfig()224 assert config.getini("strip") is bool_val225 def test_addinivalue_line_existing(self, testdir):226 testdir.makeconftest("""227 def pytest_addoption(parser):228 parser.addini("xy", "", type="linelist")229 """)230 testdir.makeini("""231 [pytest]232 xy= 123233 """)234 config = testdir.parseconfig()235 l = config.getini("xy")236 assert len(l) == 1237 assert l == ["123"]238 config.addinivalue_line("xy", "456")239 l = config.getini("xy")240 assert len(l) == 2241 assert l == ["123", "456"]242 def test_addinivalue_line_new(self, testdir):243 testdir.makeconftest("""244 def pytest_addoption(parser):245 parser.addini("xy", "", type="linelist")246 """)247 config = testdir.parseconfig()248 assert not config.getini("xy")249 config.addinivalue_line("xy", "456")250 l = config.getini("xy")251 assert len(l) == 1252 assert l == ["456"]253 config.addinivalue_line("xy", "123")254 l = config.getini("xy")255 assert len(l) == 2256 assert l == ["456", "123"]257class TestConfigFromdictargs:258 def test_basic_behavior(self):...

Full Screen

Full Screen

pytest_conftest.py

Source:pytest_conftest.py Github

copy

Full Screen

...28 # We need to apply the latest migration otherwise other tests might fail.29 call_command("migrate", verbosity=0, database=DEFAULT_DB_ALIAS)30# We reuse this file in the premium backend folder, if you run a pytest session over31# plugins and the core at the same time pytest will crash if this called multiple times.32def pytest_addoption(parser):33 # Unfortunately a simple decorator doesn't work here as pytest is doing some34 # exciting reflection of sorts over this function and crashes if it is wrapped.35 if not hasattr(pytest_addoption, "already_run"):36 parser.addoption(37 "--runslow", action="store_true", default=False, help="run slow tests"38 )39 pytest_addoption.already_run = True40def pytest_configure(config):41 if not hasattr(pytest_configure, "already_run"):42 config.addinivalue_line("markers", "slow: mark test as slow to run")43 pytest_configure.already_run = True44def pytest_collection_modifyitems(config, items):45 if config.getoption("--runslow"):46 # --runslow given in cli: do not skip slow tests...

Full Screen

Full Screen

pytestfixture.py

Source:pytestfixture.py Github

copy

Full Screen

...6##7# -*- coding: utf-8 -*-8import pytest9import qi10def pytest_addoption(parser):11 parser.addoption('--url', action='store', default='tcp://127.0.0.1:9559',12 help='NAOqi Url')13@pytest.fixture14def url(request):15 """ Url of the NAOqi to connect to """16 return request.config.getoption('--url')17@pytest.fixture18def session(url):19 """ Connected session to a NAOqi """20 ses = qi.Session()21 ses.connect(url)22 return ses...

Full Screen

Full Screen

conftest.py

Source:conftest.py Github

copy

Full Screen

1# import the option --viewloops from the JIT2def pytest_addoption(parser):3 from rpython.jit.conftest import pytest_addoption...

Full Screen

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Python 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