In any module, the special variable __name__ is defined as the name of the current module. In the command line (in IPython), this variable is set to __main__. This fact allows the following trick:
# module import ... class ... if __name__ == "__main__": # perform some tests here
The tests will be run only when the file is directly run, not when it is imported as, when imported, the variable __name__ takes the name of the module instead of __main__.