[Django]-How to ensure there are no pdb calls out of debugging configuration?

2๐Ÿ‘

โœ…

The third one. You have to enforce some commit rules. For example, run a serie of tests before a commit, etc. This way, developpers have a simple way to check if a pdb break remain. If someone commit a set_trace, he has to bake a cake for the rest of the team.

This works fine in my company ๐Ÿ™‚

edit: you may present this method to your boss as CDD (Cake Driven Developpement)

๐Ÿ‘คSimon Bergot

1๐Ÿ‘

The best option would be to have an extensive test suite, and to run the tests before pushing to production. Extraneous pdb breakpoints will prevent the tests from passing.

If you canโ€™t do that, then option 2 is the best: write a utility to break into the debugger, and make it sensitive to the state of the settings. You still have to solve the problem of how to be sure people use the wrapper rather than a raw pdb call though.

๐Ÿ‘คNed Batchelder

0๐Ÿ‘

Ideally, You shouldnโ€™t be including debugging code in the first place. You can instead use a wrapper that sets breakpoints and invokes the main program for debugging, so that the main program contains no actual set_trace() calls at all.

# foo.py
print "hello"
print "goodbye"

and

#debug_foo.py
import pdb

def run_foo():
    execfile('foo.py')

db = pdb.Pdb()
db.set_break("foo.py", 2)
db.run("run_foo()")

Example:


[~]$ python foo.py 
hello
goodbye
[~]$ python foo.py 
> <string>(1)<module>()
(Pdb) continue
hello
> /home/dbornside/foo.py(1)<module>()
-> print "goodbye"
(Pdb) continue
goodbye
[~]$ 

Leave a comment