Skip to content

Commit

Permalink
Fix test classes without TestCase as base on pytest<=2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
rudineirk committed Feb 20, 2019
1 parent 0026065 commit e8ea3dc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
16 changes: 16 additions & 0 deletions examples/test_not_subclass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pytest


def foo(arg):
return 'bar'


@pytest.fixture(params=["thing", "thang"])
def thing(request):
return request.param


class TestClassForFoo(object):
def test_foo(self, thing):
'''subsection :: test description'''
assert foo(thing) == 'bar'
14 changes: 11 additions & 3 deletions pytest_mocha/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
import re
from importlib import import_module

import pytest

MODULE_CACHE = {}
CLASS_CACHE = {}
FUNC_CACHE = {}
PYTEST_MAJOR_VERSION = int(pytest.__version__.split('.')[0])


def load_module(module_name):
Expand Down Expand Up @@ -89,12 +92,17 @@ def load_test_info(nodeid):
func_name = ''
arg_text = ''
func_text = []
if len(data) > 2:
if len(data) > 3 and PYTEST_MAJOR_VERSION <= 2:
# test classes without TestCase as base on pytest 2.x
class_name = data[1]
func_text = data[3]
elif len(data) > 2:
class_name = data[1]
func_text = data[2].split('[')
func_text = data[2]
else:
func_text = data[1].split('[')
func_text = data[1]

func_text = func_text.split('[')
func_name = func_text[0]
if len(func_text) > 1:
arg_text = '[' + func_text[1]
Expand Down

0 comments on commit e8ea3dc

Please sign in to comment.