schrodinger.test.pytest_customizations module

Local Schrodinger py.test customizations.

schrodinger.test.pytest_customizations.register_fixtures(module)[source]

Fixtures need to be registered in the pytest_customizations module.

Parameters

module – module to register pytest.fixture functions

schrodinger.test.pytest_customizations.pytest_runtest_setup(item)[source]
schrodinger.test.pytest_customizations.pytest_runtest_teardown(item, nextitem)[source]
schrodinger.test.pytest_customizations.pytest_addoption(parser)[source]
schrodinger.test.pytest_customizations.pytest_cmdline_main(config)[source]
schrodinger.test.pytest_customizations.pytest_configure(config)[source]
schrodinger.test.pytest_customizations.pytest_sessionstart(session)[source]
schrodinger.test.pytest_customizations.pytest_report_teststatus(report)[source]

Put Killed tests into a separate group from other failures.

schrodinger.test.pytest_customizations.pytest_runtest_makereport(item, call)[source]
schrodinger.test.pytest_customizations.pytest_runtest_logreport(report)[source]
schrodinger.test.pytest_customizations.pytest_collectreport(report)[source]
schrodinger.test.pytest_customizations.pytest_terminal_summary(terminalreporter)[source]
schrodinger.test.pytest_customizations.pytest_sessionfinish(session, exitstatus)[source]
schrodinger.test.pytest_customizations.pytest_unconfigure(config)[source]
schrodinger.test.pytest_customizations.pytest_collect_file(parent, path)[source]

Pytest function: Should “path” be collected as a test?

Adds compiled tests.

schrodinger.test.pytest_customizations.pytest_pycollect_makemodule(path, parent)[source]

For all Python test files, use ModuleWithPatchCheck instead of the normal pytest.Module class.

schrodinger.test.pytest_customizations.pytest_itemcollected(item)[source]

Don’t run most Python tests under memtest.

schrodinger.test.pytest_customizations.pytest_collection_modifyitems(items)[source]
schrodinger.test.pytest_customizations.pytest_collection_finish(session)[source]

Work-around for a bad cache of conftest.py

Removes the cache after all tests have been loaded. At this point, all available conftests will also be loaded, so the caching won’t be a problem. Still leaves us vulnerable to incorrect caching during test discovery, though.

See https://github.com/pytest-dev/pytest/issues/2016

schrodinger.test.pytest_customizations.pytest_addhooks(pluginmanager)[source]

Add a hook to designate an owner of each test.

class schrodinger.test.pytest_customizations.ModuleWithPatchCheck(*k, **kw)[source]

Bases: _pytest.python.Module

A Module collector that makes sure there are no active patches after module import and again after all tests in the module have completed.

teardown()[source]
name
parent
config
session
fspath
exception CollectError

Bases: Exception

an error during collection, contains a custom message.

__init__(*args, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

__init__(fspath: py._path.local.LocalPath, parent=None, config: Optional[_pytest.config.Config] = None, session: Optional[Session] = None, nodeid: Optional[str] = None) → None

Initialize self. See help(type(self)) for accurate signature.

add_marker(marker: Union[str, _pytest.mark.structures.MarkDecorator], append: bool = True) → None

dynamically add a marker object to the node.

Parameters

marker (str or pytest.mark.* object) – append=True whether to append the marker, if False insert at position 0.

addfinalizer(fin: Callable[], object]) → None

register a function to be called when this node is finalized.

This method can only be called when this node is active in a setup chain, for example during self.setup().

classnamefilter(name: str) → bool
property cls

Python class object this node was collected from (can be None).

collect() → Iterable[Union[_pytest.nodes.Item, _pytest.nodes.Collector]]

returns a list of children (items and collectors) for this collection node.

classmethod from_parent(parent, *, fspath, **kw)

The public constructor

funcnamefilter(name: str) → bool
get_closest_marker(name: str, default: Optional[_pytest.mark.structures.Mark] = None) → Optional[_pytest.mark.structures.Mark]

return the first marker matching the name, from closest (for example function) to farther level (for example module level).

Parameters
  • default – fallback return value of no marker was found

  • name – name to filter by

gethookproxy(fspath: py._path.local.LocalPath)
getmodpath(stopatmodule: bool = True, includemodule: bool = False) → str

return python path relative to the containing module.

getparent(cls: Type[_NodeType]) → Optional[_NodeType]

get the next parent node (including ourself) which is an instance of the given class

property ihook

fspath sensitive hook proxy used to call pytest hooks

property instance

Python instance object this node was collected from (can be None).

isinitpath(path: py._path.local.LocalPath) → bool
isnosetest(obj: object) → bool

Look for the __test__ attribute, which is applied by the @nose.tools.istest decorator

istestclass(obj: object, name: str) → bool
istestfunction(obj: object, name: str) → bool
iter_markers(name: Optional[str] = None) → Iterator[_pytest.mark.structures.Mark]
Parameters

name – if given, filter the results by the name attribute

iterate over all markers of the node

iter_markers_with_node(name: Optional[str] = None) → Iterator[Tuple[_pytest.nodes.Node, _pytest.mark.structures.Mark]]
Parameters

name – if given, filter the results by the name attribute

iterate over all markers of the node returns sequence of tuples (node, mark)

listchain() → List[_pytest.nodes.Node]

return list of all parent collectors up to self, starting from root of collection tree.

listextrakeywords() → Set[str]

Return a set of all extra keywords in self and any parents.

listnames() → List[str]
property module

Python module object this node was collected from (can be None).

property nodeid

a ::-separated string denoting its collection tree address.

property obj

Underlying Python object.

reportinfo() → Tuple[Union[py._path.local.LocalPath, str], int, str]
repr_failure(excinfo: _pytest._code.code.ExceptionInfo[BaseException]) → Union[str, _pytest._code.code.TerminalRepr]

Return a representation of a collection failure.

Parameters

excinfo – Exception information for the failure.

setup() → None
warn(warning: PytestWarning) → None

Issue a warning for this item.

Warnings will be displayed after the test session, unless explicitly suppressed

Parameters

warning (Warning) – the warning instance to issue. Must be a subclass of PytestWarning.

Raises

ValueError – if warning instance is not a subclass of PytestWarning.

Example usage:

node.warn(PytestWarning("some message"))