I recently started working on a python project. In that project, I am writing test cases using pytest. In that, I tried using pytest-fixtures and understood the basic concepts of it.
But I found difficulty using fixture
in a particular case, when I was trying to use these fixtures in a class
.
Sample Code:
import pytest
from flask.ext.testing import TestCase
from flask_application import app
@pytest.fixture(scope="module")
def some_fix():
return "yes"
class TestDirectoryInit(TestCase):
def create_app(self):
return app
def test_one(self, some_fix):
assert some_fix == "yes"
when I am running this test, it is throwing me an error:
TypeError: test_one() takes exactly 2 arguments (1 given)
But when I changed this code a little bit like this:
@pytest.fixture(scope="module")
def some_fix():
return "yes"
class TestDirectoryInit():
def test_one(self, some_fix):
assert some_fix == "yes"
Now this test case is getting passed. I am not able to understand that why it is behaving differently due to extending a TestCase class.
Any useful suggestion will be appreciated! Thanks!
flask.ext.testing.TestCase
is a subclass of unittest.TestCase
.
If you want to be able to use pytest fixtures with unittest, please read this:
Mixing pytest fixtures into unittest
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With