First time here? Check out the FAQ!

Testing structure problems?

NOTE: I first entered this question before I logged in. It didn't show up so I'm trying again after logging in. Sorry if there is duplication.

I am brand new to writing unit tests and thought I would give it a shot. But I've run against a problem and I suspect it is of my own making. Here is my project structure:

├── src
│   └── scanner
│       ├── __pycache__
│       └── cmd
│           └── __pycache__
└── tests
    └── unittests
        └── __pycache__

I have one simple test under unittests and it does a from scanner.cmd import CMD which works in code that resides under src. I do have src listed as the starting directory in debug/execute but when I run the simple test it says scanner isn't there.

I have pytest selected as the testing tool and it is installed OK. At least I can import pytest successfully in the python shell.

What am I not doing right?

Bill Waggoner's avatar
Bill Waggoner
asked 2020-05-21 20:39:07 -0500
Wingware Support's avatar
Wingware Support
updated 2020-05-22 10:34:32 -0500
edit flag offensive 0 remove flag close merge delete


add a comment see more comments

1 Answer


You probably need to set the Python Path in the Project Properties dialog to include the .../src directory. Python uses the python path to find module files to import. Why it works when debugging a file in the src directory is that python adds the directory of the main script file to the python path when it starts, but the main script file is the file with tests when you run unittests. This is case both when you run tests in Wing or from the command line.

Wingware Support's avatar
Wingware Support
answered 2020-05-22 09:09:25 -0500
edit flag offensive 0 remove flag delete link


Thank you. I discovered this this morning as I went through several articles on testing and pytest in particular. I now have it working in both the command-line from the root directory and in wing pro. It has already discovered one bug for me so I am way ahead of the game.

I do have one additional wing question ... the testing section didn't seem to discover my tests automatically even though they are named "correctly" and match the glob. After adding the one test file I have it tests fine but will I need to add each test individually or will it auto discover them as pytest does?

Bill Waggoner's avatar Bill Waggoner (2020-05-22 10:43:58 -0500) edit

Test files should be found if they match a pattern in Wing's project properties dialog. If they are not found, could you submit a bug report from Wing's Help menu with the log attached. Tests discovered by pytest are not automatically added in Wing.

Wingware Support's avatar Wingware Support (2020-05-22 11:33:56 -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