First time here? Check out the FAQ!

Using relative import in a test file

I have a tests module which ends with if_name_ = '__main--' : import unittest unittest.main().

I would like to be able to use relative imports in the module. if I used a launch configuration I get a no parent package error, which is confirmed by a print at the top of the module where package is None. My understanding is that therefore I should launch it as a module with python -m When I select this option and add the name of the module as a run argument in the form of parent_package.module wing refuses to laucnh the module sayin it needs a dotted name.

Do you have a hint to launch this module as a main. I thank you in advance.

PS. I have a in the same directory as my test module. and the parent.parent.parent directory is in the python Path

piscvau's avatar
asked 2023-06-24 09:27:18 -0500
Wingware Support's avatar
Wingware Support
updated 2023-07-01 07:43:29 -0500
edit flag offensive 0 remove flag close merge delete


Are you trying to launch through the Testing tool or directly using the debugger? If you're using the Testing tool, it should be launching as a package module because exists, but you can also change the Run As Package Module setting to Run As Package Module ... on the Testing page of the Project Properties dialog. Make sure that the parent (or grandparent) directory of the package is in the Python path.

If you're launching the debugger directly, it should work to use Debug > Debug Current File and then select Launch with 'python -m' ... in the pre-launch dialog box. There's no need to enter the package or module name.

Note that the if __name__ == '__main__': logic probably isn't correct if you're launching with python -m because the __name__ will be the name of module within the package so if the file in named, the __name__ ... (more)

Wingware Support's avatar Wingware Support (2023-06-26 06:25:50 -0500) edit

Thank you for you answer and the remark about the if __name__==__main__ logic which is obviously wrong. I am using the debugger directly. I do Debug File and choose the python -m option . Then I get the following error message : some values are invalid. The module name for the file needs to be a dotted name. Please correct the values and try again.

piscvau's avatar piscvau (2023-06-26 15:03:06 -0500) edit

Does it work if you add this file to the Testing tool and debug from there instead?

Wingware Support's avatar Wingware Support (2023-06-27 09:09:27 -0500) edit

HelloI think I cannot do this. I am in a django project and want to debug a test-file with unittest. My understainding is that I need to configure file properties (right click on the file in the editor) and select from there the python -m option. And this is where the problem occurs (error message requiring a dotted name for the module).

piscvau's avatar piscvau (2023-06-28 04:14:51 -0500) edit

I suspect you need a different dotted name. You said parent.parent.parent is on the Python Path so I'd expect you would need parent.parent.modulename as the dotted name for -m. I could be misunderstanding, though. If you can make a simple example to pack up and email us at that might clarify it.

Wingware Support's avatar Wingware Support (2023-06-28 07:49:03 -0500) edit
add a comment see more comments

1 Answer


Hello the new release does solve the problem and python -m works.

piscvau's avatar
answered 2023-07-01 02:31:23 -0500
edit flag offensive 0 remove flag delete link


Thanks for confirming this!

Wingware Support's avatar Wingware Support (2023-07-01 07:45:46 -0500) edit
add a comment see more comments

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss.

Add Answer