Mark Banford
Mark Banford

Reputation: 43

Unit Test in Python assertIsNotNone

I am completely new to unit testing and cannot see why i am getting an 'AssertionError: unexpectedly None'

my test in written as

import unittest
from Extraction import Core

class testDict(unittest.TestCase):

    def test_dict_populate(self):
        result=Core(file='input.txt')
        self.assertIsNotNone(result)

from the Extraction file is my Core function

def Core(file):
    with open(file) as f:
        for line in f:
        # populate auction item
            if 'SELL' in line:
            auctionsplit = (line.strip().split('|'))
            new_item = auction(auctionsplit)
            dct[new_item] = []

            elif 'BID' in line:
                tokens = (line.strip().split('|'))
                new_bid = bid(tokens)
                bid_item_id = new_bid.item
                key_to_update = find_item(bid_item_id, dct.keys())
                dct[key_to_update].append(new_bid)
            else:
                pass

The input file is stored in the same project as the test and Core so am abit confused tbh

Upvotes: 0

Views: 2410

Answers (1)

Andreas Samuelsson
Andreas Samuelsson

Reputation: 66

Your function Core does not return a value. In python, a function that doesn't return a value implicitly returns None. In the testcase, result gets assigned to None and the test case fails.

You probably want Core to return something

Upvotes: 3

Related Questions