Skip to content

pytest fixture can't be used when testcase extends of BaseCase #745

Closed
@cw1427

Description

@cw1427

SeleniumBase version=1.50.1
Python=3.6.8
OS=Windows

When I customized a fixture named tap_testcase_config, and write below two kinds of testcase, one extends of BaseCase, one is a pure testcase. Only pure testcase could pass when use my customized fixture.
The same as built-in sb fixture. Please see below error

`from seleniumbase import BaseCase

class MyTestClass(BaseCase):

def test_demo_site(self, tap_testcase_config):
    pass

class MyTestClass1():

def test_demo_site1(self, tap_testcase_config):
    pass

`

`
$ pytest ./test.py
============================= test session starts =============================
platform win32 -- Python 3.6.4, pytest-6.1.1, py-1.9.0, pluggy-0.13.1
rootdir: E:\opt\tools\newgam\taptest_base, configfile: pytest.ini
plugins: allure-pytest-2.8.18, celery-4.3.0, cov-2.10.1, forked-1.3.0, html-2.0.1, metadata-1.10.0, ordering-0.6, rerunfailures-9.1.1, xdist-2.1.0, seleniumbase-1.50.1
collected 2 items

test.py F.

================================== FAILURES ===================================
_________________________ MyTestClass.test_demo_site __________________________

self = <unittest.case._Outcome object at 0x0000014A048DEEF0>
test_case = <taptest_base.test.MyTestClass testMethod=test_demo_site>
isTest = True

@contextlib.contextmanager
def testPartExecutor(self, test_case, isTest=False):
    old_success = self.success
    self.success = True
    try:
      yield

c:\program files\python36\Lib\unittest\case.py:59:


self = <taptest_base.test.MyTestClass testMethod=test_demo_site>
result =

def run(self, result=None):
    orig_result = result
    if result is None:
        result = self.defaultTestResult()
        startTestRun = getattr(result, 'startTestRun', None)
        if startTestRun is not None:
            startTestRun()

    result.startTest(self)

    testMethod = getattr(self, self._testMethodName)
    if (getattr(self.__class__, "__unittest_skip__", False) or
        getattr(testMethod, "__unittest_skip__", False)):
        # If the class or method was skipped.
        try:
            skip_why = (getattr(self.__class__, '__unittest_skip_why__', '')
                        or getattr(testMethod, '__unittest_skip_why__', ''))
            self._addSkip(result, self, skip_why)
        finally:
            result.stopTest(self)
        return
    expecting_failure_method = getattr(testMethod,
                                       "__unittest_expecting_failure__", False)
    expecting_failure_class = getattr(self,
                                      "__unittest_expecting_failure__", False)
    expecting_failure = expecting_failure_class or expecting_failure_method
    outcome = _Outcome(result)
    try:
        self._outcome = outcome

        with outcome.testPartExecutor(self):
            self.setUp()
        if outcome.success:
            outcome.expecting_failure = expecting_failure
            with outcome.testPartExecutor(self, isTest=True):
              testMethod()

E TypeError: test_demo_site() missing 1 required positional argument: 'tap_testcase_config'

c:\program files\python36\Lib\unittest\case.py:605: TypeError
=========================== short test summary info ===========================
FAILED test.py::MyTestClass::test_demo_site - TypeError: test_demo_site() mis...
========================= 1 failed, 1 passed in 6.58s =========================
(env36)

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalid usageYou may need to change what you're doingquestionSomeone is looking for answers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions