Stacey
Stacey

Reputation: 5097

Trying to run a unittest module

I have created a unittest module called test_blbmktdata.py to test some code. I am trying to run it from the console using the following command:

run test_blbmktdata.py

However I get the error message:

ERROR:root:File `'test_blbmktdata.py'` not found.

Please see below for the module code.

import unittest

class TestBlbMktData(unittest.TestCase):
    staticName='StaticInstrumentData.csv'


    def print(self,data):
        print()
        print(len(data))
        print(data.head())
        print(data.dtypes)

    def read(self,name,func):
        return func(os.path.join(self.current_dir,name))

    def setUp(self):
        self.current_dir=os.path.dirname(os.path.abspath(__file__))

    def test_corp_act(self):
        self.print(self.read(self.corpName,readCorpAction))
     
if __name__ == '__main__' :
    unittest.main()    

How can I run the code from the console?

Upvotes: 0

Views: 135

Answers (2)

PunyCode
PunyCode

Reputation: 373

For running a python code say code.py you can simply use command

python code.py

on the terminal after you navigate to the same directory where code is located.

Upvotes: 0

Kamal Hasan
Kamal Hasan

Reputation: 26

Try python -m unittest test_blbmktdata in terminal https://docs.python.org/2/library/unittest.html#command-line-interface

Upvotes: 1

Related Questions