0

My conftest.py

@pytest.fixture(scope="class")
def prepare_test_dataframe():
    try:
        with pd.ExcelFile(TEST_INPUT_DIR + TEST_FILE_NAME) as xls:
            for sheet_name in xls.sheet_names:
                if sheet_name == "TESTSHEET1":
                    test_df = pd.read_excel(TEST_INPUT_DIR + TEST_FILE_NAME, sheet_name=sheet_name, header=None)
    except IOError:
        print("Cannot open file")

    return test_df

test.py

@pytest.mark.usefixtures("prepare_test_dataframe")
class TestConvertXLS_Scad(unittest.TestCase):
    def test_add_units_columns(self, prepare_test_dataframe):
        test_merged_cells = [[1, 37, 1, 43], [1, 35, 1, 36]]
        test_df = prepare_test_dataframe
        actual_df = self.mymod.add_units_columns(test_df, test_merged_cells)

        # compare results
        self.assertEqual(actual_df.loc[32, "A"], 2.0)

Traceback:

TypeError: test_add_units_columns() missing 1 required positional argument: 'prepare_test_dataframe'

I've been reading through other posts and the documents, but I can't seem to resolve this issue. Where am I going wrong?

pymat
  • 1,090
  • 1
  • 23
  • 45
  • You cannot mix pytest fixtures with unittest tests, as unittest does not know about pytest. Is there a reason why you need to use `unittest`? – MrBean Bremen Feb 08 '21 at 11:52
  • @MrBeanBremen, I guess it'S not essential to have unittest, if I use something else. Any recommendations? – pymat Feb 08 '21 at 12:10
  • Well, you are obviously using pytest already - so just use pytest. Don't derive your test classes from `unittest.TestCase`, and use `assert` instead of `assertXXX`. – MrBean Bremen Feb 08 '21 at 13:12

0 Answers0