When I run tests, there are different ways. You can right click and run on:
- triangle next to test
- triangle next to test class definition
- space in the file above the test class
For some reason, all of these create a new environment, which doesn’t follow the template. Whenever I write a new test, I go over this whole process of automatically creating some random environment, failing the test, editing the environment and saving it, rerunning the test.
It feels like PyCharm has some weird setting that I cannot find and override.
I see that PyCharm recognized that I use unittest library when I went to Settings/Python Integrated Tools/Testing/Default Test Runner.
Also, when from the configuration drop down I choose Edit configuration templates I do one for unittests with the correct working directory.
Also, I’ve never had this issues with older versions of PyCharm. With the current one I see the file directory can be defined by Module name, Script path or Customized. Automatically created environments place some module directory , separated by dots like automated_update_eu_test.AutomatedUpdateEUTest.test_EU_source_import . Weirdly enough, I didn’t create init in that directory, but these are the configurations that run the tests successfully.
I also tried with or without
if name == ‘main‘:
unittest.main()
but it makes no difference.
Калин Кръстев is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.