Ask Your Question

Testing structure problems?

asked 2020-05-21 20:39:07 -0600

Bill Waggoner gravatar image

updated 2020-05-22 10:34:32 -0600

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?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2020-05-22 09:09:25 -0600

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.

edit flag offensive delete link more


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 gravatar imageBill Waggoner ( 2020-05-22 10:43:58 -0600 )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 gravatar imageWingware Support ( 2020-05-22 11:33:56 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2020-05-21 20:39:07 -0600

Seen: 136 times

Last updated: May 22 '20