plugin module¶
-
pytest_addhooks
(pluginmanager: PytestPluginManager) → None[source]¶ Add new hooks.
- Parameters
pluginmanager (_pytest.config.PytestPluginManager) –
- Returns
None
-
pytest_configure
(config: Config) → None[source]¶ Perform initial configuration as follows:
Add
pytest.mark.option
marker to the ini-file option.
- Parameters
config (_pyest.config.Config) – pytest config object.
- Returns
None
Note
This is a
pytest hook function
which is called for every plugin and initial conftest file after command line options have been parsed. After that, the hook is called for other conftest files as they are imported.
-
pytest_collection_modifyitems
(items: List[Item]) → None[source]¶ Modify the items collected by pytest as follows:
Because all test items using pyppeteer should be an asyncio coroutine, here the pytest.mark.asyncio marker is automatically added to each test item collected by pytest.
- Parameters
items (List[pytest.Item]) – the list of items objects collected by pytest.
- Returns
None
Note
This is a
pytest hook function
which is called after collection of all test items is completed.
-
add_asyncio_marker
(item: Item) → Item[source]¶ Add pytest.mark.asyncio marker to the specified item.
If the marker is already exists, return the item directly.
- Parameters
item (pytest.Item) – the pytest item object.
- Returns
the marked item object.
-
is_coroutine
(obj: Any) → bool[source]¶ Check to see if an object is really an asyncio coroutine.
- Parameters
obj (Any) – any object.
- Returns
True or False.
-
pytest_runtest_makereport
(item: Item) → None[source]¶ Implement this pytest hook in wrapper mode, the added behaviors as follows:
Register a new
hooks.pytest_pyppeteer_runtest_makereport_call_debug()
hook which called when a actual failing test calls not setup/teardown.
- Parameters
item (pytest.Item) – the pytest item object.
- Returns
None
-
pytest_addoption
(parser: Parser) → None[source]¶ Register new command line arguments and ini-file values.
Create a new command line option group named pyppeteer, and add the following new options in it:
--executable-path
: path to a Chromium or Chrome executable.--headless
: run browser in headless mode.--args
: additional args to pass to the browser instance. more details refer toargs()
fixture.--window-size
: set the initial browser window size. Defaults to 800 * 600.--window-size 0 0
means to starts the browser maximized.--slow
: slow down the pyppeteer operate in milliseconds. Defaults to0.0
.
- Parameters
parser (_pytest.config.argparsing.Parser) – parser for command line arguments and ini-file values.
- Returns
None
Note
This is a
pytest hook function
which be called once at the beginning of a test run to register argparse-style options and ini-style config values.There are two ways to register new options, respectively:
To register a command line option, call
parser.addoption(...)
.To register an ini-file option, call
parser.addini(...)
.
And the options can later be accessed through the
Config
object, respectively:To retrieve the value of a command line option, call
config.getoption(name)
.To retrieve a value read from an ini-style file, call
config.getini(name)
.
The
Config
object is passed around on many pytest internal objects via the.config
attribute or can be retrieved as thepytestconfig
fixture.
-
executable_path
(pytestconfig: Config) → Optional[str][source]¶ Session-scoped fixture
that return Chrome or Chromium executable path.The fixture behaviors follow this procedure:
Return the value passed in from command line option of –executable-path, if it’s not
None
.Return the default installation location of Chrome in current platform, but now only support
win64
,win32
andmac
platform.For other platforms, pyppeteer will downloads the recent version of Chromium when called first time. If you don’t prefer this behavior, you can specify an exact path by overwrite this fixture:
Example:
@pytest.fixture(scope="session") def executable_path(executable_path): if executable_path is None: return "path/to/Chrome/or/Chromium" return executable_path
- Parameters
pytestconfig (_pytest.config.Config) – a session-scoped fixture that return config object.
- Returns
return Chrome or Chromium executable path string. but if current platform isn’t supported, return
None
.
-
args
(pytestconfig: Config) → List[str][source]¶ Session-scoped fixture
that return a list of additional args in the List of Chromium Command Line Arguments to pass to the browser instance.You can use it by command-line option:
Example:
$ pytest --args proxy-server "localhost:5555,direct://" --args proxy-bypass-list "192.0.0.1/8;10.0.0.1/8"
Or overwrite it in your test:
Example:
@pytest.fixture(scope="session") def args(args) -> List[str]: return args + [ "--proxy-server=localhost:5555,direct://", "--proxy-bypass-list=192.0.0.1/8;10.0.0.1/8", ]
- Parameters
pytestconfig (_pytest.config.Config) – a session-scoped fixture that return config object.
- Returns
a list of arguments string. return
list()
if no--args
passed in the command-line.
-
session_options
(pytestconfig: Config, args: List[str], executable_path: str) → Options[source]¶ Session-scoped fixture
that return amodels.Options
object used to initialize browser.- Parameters
pytestconfig (_pytest.config.Config) – a session-scoped fixture that return config object.
args (List[str]) – a session-scoped fixture that return a list of additional args to pass to the browser instance.
executable_path (str) – a session-scoped fixture that return Chrome or Chromium executable path.
- Returns
a
models.Options
object used to initialize browser.
-
options
(request: FixtureRequest, session_options: Options) → Options[source]¶ Function-scoped fixture
that return amodels.Options
object used to initialize browser.This fixture contains all of
session_options()
, plus any options specified by the options markers. Any change to these options will apply only to the tests covered by scope of the fixture override.Example:
@pytest.mark.options(devtools=True) async def test_options_mark(pyppeteer): ...
- Parameters
request (_pytest.fixture.FixtureRequest) – A request object gives access to the requesting test context.
session_options (Options) – a
models.Options
object fromsession_options()
.
- Returns
a
models.Options
object used to initialize browser.
-
get_options_from_markers
(item: Item) → dict[source]¶ Get the options from the
options
markers of test item. And there are only apply on the current test item.- Parameters
item (Item) – the test item object.
- Returns
an dict contains options.
-
pyppeteer_factory
(options: pytest_pyppeteer.models.Options) → Callable[source]¶ Function-scoped fixture
that return a pyppeteer browser factory.- Parameters
options (Options) – a
models.Options
object used to initialize browser- Yield
a pyppeteer browser factory.