Hi, I am having trouble with running some Function tests with py.test via Wing.
I have created a fixture which calls some code which includes some argparse logic. I need to be able to detect when the code is being called via a Unit test, so that I can workaround the argparse code as it will be receiving Wing's command line arguments.
The best I can think of is something like sys.argv.find('Wing IDE 5.1') > 0
Is there a better way?
Also Wing seems to consume & hide errors encountered during the fixture. ie. If I fail to detect that the code is being called by py.test running under Wing, then argparse logic tries to parse Wing's arguments, causing argparse to issue a sys.exit()
In the Wing IDE I just see a little red x against the test, but no diagnostic message, neither are any of the print statements displayed.
If I run the same test outside of Wing, py.test displays the failing line number, stack trace etc.
Is there any way to get Wing to display this information?
Wing IDE users list
Barry Mossman via wingide-users wrote:
> Hi, I am having trouble with running some Function tests with py.test
> via Wing.
> I have created a fixture which calls some code which includes some
> argparse logic. I need to be able to detect when the code is being
> called via a Unit test, so that I can workaround the argparse code as
> it will be receiving Wing's command line arguments.
> The best I can think of is something like sys.argv.find('Wing IDE
> 5.1') > 0
> Is there a better way?
Are you running this from the Testing tool or some other way? We try to
set up sys.argv so it's correct and I didn't think it would contain
anything like 'Wing IDE 5'. Can you send me the full contents of sys.argv?
If you can send a small test case along with which pytest version you're
using that may be the easiest way to diagnose this. You can send that
to [hidden email].
Wingware | Python IDE
The Intelligent Development Environment for Python Programmers
Wing IDE users list
I am using your testing tool.
I don't think that there is any "correct" expectation for sys.argv in this case.
I have a fairly large Python app with many source modules. It is just one application. but has various run modes. Each of the run modes use some common modules; one of these central modules handles generic run option parsing, another handles db access, etc.
I am building some function tests.
When the app is running in production it gets called with some run arguments
For my function test, I just have a fixture which imports a couple of the central modules, and also the ones required for the function test. You, or py.test, run this test, so there are no run arguments. ... I am not testing the whole app, just one of the modules.
So I wasn't expecting anything specific in sys.argv, although something which enabled my production module to detect that it was being called inside a unit test would have been helpful.
I have worked around this by passing an argument into the imported module, telling it that it is being unit tested, and passing it a set of run arguments to use. .... I still think that it would be useful to be able to detect that code is being unit tested, by you putting some data switch in your sys.argv ?
I see your sys.argv as:
['C:\\Program Files (x86)\\Wing IDE 5.1\\src\\testing\\runners\\run_pytest_xml.py', '--directory=d:\\Do Not Backup\\Temp stuff\\wing', '-q', 'test_wing.test_wing', '--no-xml']
I probably should have mentioned that I am running under Windows.
The bigger problem is that Wing is consuming and hiding errors in some circumstances.
When I run the test using the Wing test facility I just see a little red x alongside the test. No error messages. No print statements while trying to debug.
When I run the test outside wing, via py.test, I see error stacks, error statement, etc. ... ie. in this case argparse has issued SystemExit: 2 because it couldn't find a valid positional argument in sys.argv which has been passed to it.
I have sent a small python test file to your email address which demonstrates this.
thanks for looking into it
Wing IDE users list
|Free forum by Nabble||Edit this page|