Reputation: 2023
I was reading about pytest-expect and tried the code they have given as a example
import pytest
def test_func(expect):
expect('a' == 'b')
expect(1 != 1)
a = 1
b = 2
expect(a == b, 'a:%s b:%s' % (a,b))
on the terminal I have given command as
py.test test.py
getting error as below
def test_func(expect):
E fixture 'expect' not found
> available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, monkeypatch, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
> use 'pytest --fixtures [testpath]' for help on them.
Do I need to defind expect
somewhere?
Upvotes: 0
Views: 1005
Reputation: 698
I reproduced your error locally and then found documentation of pytest-expect from which the sample code came from.
I tried to find the source code for pytest-expect
: what I found was this GitHub issue where the author of that package commented "Seems that there are two different "pytest-expect" packages!" So I thought, OK, so it's just a matter of confirming that we pull the exact correct version of the package, right?
Going back to the docs from which the code sample in the question comes from, down below we see a link to pytest-expect code now in a github repo. This repo does seem to contain the appropriate expect
fixture, but the README.md indicates that "This repo is archived. Further development of this feature has moved to pytest-check."
The demo code provided for pytest-check does indeed work to allow multiple "checks" to be executed in a single test.
import pytest_check as check
def test_example():
a = 1
b = 2
c = [2, 4, 6]
check.greater(a, b)
check.less_equal(b, a)
check.is_in(a, c, "Is 1 in the list")
check.is_not_in(b, c, "make sure 2 isn't in list")
pytest
pytest-check
First pip install -r requirements.txt
and then run pytest test.py
.
Upvotes: 2