Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit tests in pycharm are running twice

I need to generate a test report using HTMLTestRunner ,for that code (which is placed at the end of the file) is:

suite = unittest.TestLoader().loadTestsFromTestCase(TestLoginPages)

outfile = open("/home/xxx/xxx/xxxx/report.html", "w")
runner = HTMLTestRunner.HTMLTestRunner(
    stream=outfile,
    title='Test Report',
    description='Test report for the application')
runner.run(suite)

Then I run the test cases from pycharm ,all the tests are running twice. I have tried to 'Edit Configurations' in the 'Run' menu where I delete the 'unittest in my_file_name' configuration, but issue remains same

like image 219
Avanti Avatar asked Oct 20 '15 06:10

Avanti


1 Answers

Make sure your manage.py file contains

if __name__ == "__main__":
    ...
    execute_from_command_line(sys.argv)

PyCharm tries to make import of manage.py file to be sure there are no import errors. If your manage.py file does not contain name == "main" validation, then tests run on import stage as if they were launched from the bash and then PyCharm runs them directly once more.

like image 136
Kirill Emelyanov Avatar answered Oct 20 '22 00:10

Kirill Emelyanov