North
North

Reputation: 21

how to debug twisted trial unittest in pycharm

I am new to twisted and I have a twisted unit test in python, and I want to debug in pycharm with trial.

I can run the tests in command line fine (for e.g. like :~ nathan$ trial smoke_tests ) but would like to step through the test in an IDE

in another question How debuging twisted application in PyCharm

It has been suggested that "configure the "Script" setting to point to that twistd" . so for 'trial' I tried pointing to /Library/Python/2.7/site-packages/twisted/trial/runner.py , but that fails.

Upvotes: 1

Views: 860

Answers (1)

Alok A
Alok A

Reputation: 271

Script Assuming your working directory is /home/myself/mypythonproject/myworkingdirectory ,

Create a python file in your working directory with name trial_try.py. This is a copy of /usr/local/bin/trial. So use a copy of the version you have.

    import os, sys

    try:
         import _preamble
    except ImportError:
        try:
            sys.exc_clear()
        except AttributeError:
            # exc_clear() (and the requirement for it) has been removed from Py3
        pass

    # begin chdir armor
    sys.path[:] = map(os.path.abspath, sys.path)
    # end chdir armor

    sys.path.insert(0, os.path.abspath(os.getcwd()))

    from twisted.scripts.trial import run
    run()

Configuration Create a new Run Configuration in Pycharm.

for Script Enter

/home/myself/mypythonproject/myworkingdirectory/trial_try.py

for Parameters Enter you Parameters that you would use when running trial on the command line

for e.g. test_smoke

for Working directory Enter

/home/myself/mypythonproject/myworkingdirectory

You should be all Set !

Upvotes: 1

Related Questions