-2

I have the following to see if a DataFrame is empty or not:

def emptyframecheck(data_frame):
if data_frame.empty:
    raise Exception('An empty dataframe was passed.')

I would like to unit test this but when I run this:

def test_emptyframecheck():
    # Given
    workitem_df = pd.read_csv(os.path.join(HERE, 'test_csv', 'test.csv'))

    # When
    emptyframecheck(workitem_df)

    # Then
    assertTrue('An empty dataframe was passed' in emptyframecheck.exception)

I am getting a global name assertTrue is not defined. The workitem_df is simply an empty frame I am passing. Is there something I am missing or a better approach?

Sheldore
  • 37,862
  • 7
  • 57
  • 71
skimchi1993
  • 189
  • 2
  • 9
  • 1
    Maybe you mean pytest.assertTrue or whatever external module you're using for testing – N Chauhan Aug 23 '18 at 16:34
  • Possible duplicate of [How to properly assert that an exception gets raised in pytest?](https://stackoverflow.com/questions/23337471/how-to-properly-assert-that-an-exception-gets-raised-in-pytest) – hoefling Aug 23 '18 at 21:14

1 Answers1

1

This error means what it says: assertTrue is not defined. Have you imported assertTrue? If you imported the testing module but not the framework, you'll have to do:

testing_module.assertTrue()

If you want to use 'assertTrue` directly, you should write at the top of the test file the following:

from testing_module import assertTrue
N Chauhan
  • 3,407
  • 2
  • 7
  • 21
Nathan Hinchey
  • 1,191
  • 9
  • 30