missing 1 required positional argument error for fixture when softest.TestCase in inherited

Viewed 1190

I am getting error missing 1 required positional argument for fixture when i inherite softest.TestCase

note : if i remove softest.TestCase test will execute but failes when used. my pytest code as below :

Content of test_compyte.py

import softest

class Testcompute (softest.TestCase):

    def test_compute(self,param1):
        print("param is ",param1)
        assert param1 > 4

if __name__ == '__main__':
    softest.main()

Content of conftest.py

import pytest
import selenium
from selenium import webdriver

def pytest_addoption(parser):

    parser.addoption("--templatename", action="store", help="run all combinations")


def pytest_generate_tests(metafunc):

    if "param1" in metafunc.fixturenames:
        if metafunc.config.getoption("templatename"):
            end = int(metafunc.config.getoption("templatename"))
        else:
            end = 1
        metafunc.parametrize("param1", range(end))

Error logs

self = <parameter.test_compute.Testcompute testMethod=test_compute>
method = <bound method Testcompute.test_compute of <parameter.test_compute.Testcompute testMethod=test_compute>>

    def _callTestMethod(self, method):
>       method()
E       TypeError: test_compute() missing 1 required positional argument: 'param1'

 TypeError
================================================================ short test summary info =================================================================
FAILED test_compute.py::Testcompute::test_compute - TypeError: test_compute() missing 1 required positional argument: 'param1'
1 failed in 0.22s
1 Answers

Work around solution: instead of inheriting softest.TestCase, create an object of softest.TestCase inside the test.

Updated content of test_compyte.py:

class Testcompute: 
    def test_compute(self, param1): 
        case = softest.TestCase() 
        print("param is ", param1) 
        assert param1 > 4 

if name == 'main': 
    softest.main()
Related