Hello.
I have been working with pytest instead of nosetest since ex47. It has been a little easier to find documentation for pytest.
Now I have run into a problem I could not find the solution for. In ex49 one should test a failure (raise exception).
I tried to get the ParserError to “trigger”. My code looks like this:
import pytest
from parser import ParserError, Sentence, match, parse_sentence, parse_subject
@pytest.fixture()
def sentences():
pass
y = parse_sentence([('noun','princess'),('verb','run'),('direction','away')])
return y
def test_parse_sentences(sentences):
assert sentences.subject == 'princess'
assert sentences.verb == 'run'
def test_parse_sentence():
"""the same test as above without a fixture"""
x = parse_sentence([('noun','princess'),('verb','run'),('direction','away')])
assert x.subject == 'princess'
assert x.verb == 'run'
assert x.obj == 'away'
def test_match():
pass
word_list = [('noun','princess'),('verb','run'),('direction','away')]
ord = word_list.pop(0)
assert ord[0] == ('noun')
def test_parse_subject():
x = parse_sentence([('noun','princess'),('verb','go'), ('direction','away')])
with pytest.raises(ParserError):
assert x.verb == 'go'
assert x.subject == 'princess'
The output will be like this:
platform linux -- Python 3.5.2, pytest-3.2.3, py-1.4.34, pluggy-0.4.0 -- /home/ulf/LPTHW/hardway/bin/python3
cachedir: .cache
rootdir: /home/ulf/LPTHW, inifile:
collected 4 items
test_expecting.py::test_parse_sentence PASSED
test_expecting.py::test_match PASSED
test_expecting.py::test_parse_sentences PASSED
test_expecting.py::test_parse_subject FAILED
================================== FAILURES ==================
_____________________________ test_parse_subject ______________________
def test_parse_subject():
x = parse_sentence([('noun','princess'),('verb','go'), ('direction','away')])
with pytest.raises(ParserError):
assert x.verb == 'go'
> assert x.subject == 'princess'
E Failed: DID NOT RAISE <class 'parser.ParserError'>
test_expecting.py:38: Failed
===================== 1 failed, 3 passed in 0.02 seconds ==========
Need some help to get on track again.
Am I close? Or miles adrift?