7

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

Avanti
  • 323
  • 5
  • 14
  • You ever figure this out? – Pat K Jan 05 '16 at 01:33
  • @PatK , sadly no, When I have to generate a test report I run the test cases from terminal not pycharm – Avanti Jan 06 '16 at 03:22
  • I ran into a case where this was caused by a unit test file that had a relative import of something in a different unit test file in the same directory: `from .other_test import ...` for example. – Shawn Apr 08 '21 at 22:18

2 Answers2

1

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.

  • Perfect! I just ran into this with PyCharm 2017.2.3 and your solution resolved the issue. Thanks! – JFlo Sep 20 '17 at 15:26
-2

Tried

  • Restarting Couple of times
  • Reinstalling entire eco system
  • Re-cloning of project

But didn't work

Solution: What worked for me Pycharm: Setting -> Project-> Project Interpreter

It should not contain more than 1 runner of your test runner

In my case I had behave and behave-parallel I removed behave-parallel and every thing become normal.

I hope this will help you.

user2206324
  • 356
  • 2
  • 8