From Linux mint bash I type
$ pytest tests/parser_test.py
=============================== test session starts py ================================
platform linux2 -- Python 2.7.14, pytest-3.2.1, py-1.4.34, pluggy-0.4.0
rootdir: /home/rat/Projects/ex48, inifile:
collected 0 items
=========================== no tests ran in 0.00 seconds ===========================
and yet it says there are "no test ran". I did each function test in stages and it worked for a while but I noticed that with each additional function pytest was picking up less test(s). I have a funny feeling it is with my testing code, however I am not sure what it is that I am doing wrong or even what to search for it. I tried changing some of the variables from word_list_one to wl_one to see if that was the problem with no success. I also check stack over similar questions but could not find the answer. I must admit this is my first language that I have learnt so I'm very new to this whole testing thing. Here is my Project tree
.
├── ex48
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── lexicon.py
│ ├── parser.py
│ └── parser.pyc
├── README.md
├── setup.py
└── tests
├── __init__.py
├── __init__.pyc
├── lexicon_tests.py
├── parser_test.py
└── __pycache__
├── parser_test.cpython-27-PYTEST.pyc
└── parser_tests.cpython-27-PYTEST.pyc
import pytest
from ex48 import parser
from ex48.parser import Sentence
# test parse_sentence
@pytest.fixture()
def test_sentence():
sentence = Sentence.parse_sentence([("noun","player"),("verb", "go"),("noun", "bear")])
return sentence
def test_peek():
result = test_sentence()
assert Sentence.peek(result) != None
After removing @classmethod, correct answer from hansaplast, I needed to change the test_sentence and added test_sentence(self) to ```as1 per this answer:
@pytest.fixture()
def test_sentence(self):
sentence = Sentence()
return sentence.parse_sentence([("noun","player"),("verb", "go"),("noun", "bear")])
However now I have an issue with the pytest fixture
$ pytest tests/parser_test.py
============================== ERRORS ====================================
___________________ ERROR at setup of test_peek __________________________
file /home/rat/Projects/ex48/tests/parser_test.py, line 13
def test_peek(test_sentence):
file /home/rat/Projects/ex48/tests/parser_test.py, line 7
@pytest.fixture()
def test_sentence(self):
E fixture 'self' not found
> available fixtures: cache, capfd, capsys, doctest_namespace,
monkeypatch, pytestconfig, record_xml_property, recwarn,
test_sentence, tmpdir, tmpdir_factory
> use 'pytest --fixtures [testpath]' for help on them.
So I typed $ pytest --fixtures tests/parser_test.py and received a lot of information that doesn't make sense to me and this:
------------- fixtures defined from tests.parser_test -------------------
test_sentence
tests/parser_test.py:8: no docstring available
Might be easier to delete and start over without @pytest.fixtures =^/