Ex 49 testfunctions do not run

While running the test for the parser I noticed that my testfunctions for the parser do not run:

import pytest
from exc48 import parser, lexicon

def sentence_test():
    result = lexicon.scan("princess kills bear")
    assert parser.Sentence(result) == "noun""verb""noun"


def peek_test():
    assert peek([('noun', 'bear')]) == 'noun'
    assert peek("wallstreet") == none

With this code I get the following:

At first, I thought that for some reason the parser_test wasn’t running. But to test that I put in some extra code:

import pytest
from exc48 import parser, lexicon

def sentence_test():
    result = lexicon.scan("princess kills bear")
    assert parser.Sentence(result) == "noun""verb""noun"


def peek_test():
    assert peek([('noun', 'bear')]) == 'noun'
    assert peek("wallstreet") == none

def test_test():
    x = 1
    y = 1
    assert x == y

When I pytest this it does show that the file is running:

So the testfile is running but the tests I have made in the testfile are not. I could find a lot on youtube about how to make a testfile running but not about why I certain testfunction within a testfile would not run.

If the importing was not working or the input of the testfunction would be wrong then I would atleast expect an error.

On top of this. If I mess up the code by putting comma’s like this:

assert parser.Sentence(result) == "noun","verb","noun"

It will give me an error:

So it seems like it does run the testfunction. But if it does not have any mistakes inside of it, it doesn’t test anything.

Have been struggling with this for a while, any help would be appreciated.

Pytest only executes functions that match certain detection patterns. It’s been a while since I’ve done Python testing, but I guess the function name must start with “test…”?

1 Like

Oh my god. Right. Thanks.

1 Like

I have another question about one of the study drills. It asks to make classes out of the functions and after that which design feels better.

One of the functions I transformed into a class looks like this:

class parse_subject(object):

    def __init__(self,word_list):
        self.word_list = word_list

    def parse_subject(word_list):
        skip(word_list, 'stop')
        skip(word_list, 'error')
        next_word = peek(word_list)

        if next_word == 'noun':
            return match(word_list, 'noun')
        elif next_word == 'verb':
            return ('noun', 'player')
        else:
            raise ParserError("Expected a verb or noun next.")

And the answer to the question asked in the study drill would be:

I like functions better because they are less code, and I do not fully understand how classes would make my life easier.

Should my conception of classes be better at this point? I feel my answer is very lackluster.

Thanks in advance!