Proving that my python changes are being hit



  • My experience in the past has been either .Net or Java. I've done a smattering of python, but this is my first python job.

    I want to prove that my change to an existing python script is being hit. The python script I'm trying to change is called by another script, which is called by another script, which is called by a shell script.

    If I make a test script in the same directory, and I make it executable, I can run the script and it will create a file, which proves that the code was hit. (Not that there was any doubt about the test script.)
    Edit: The script does not have logging permissions when it is called by the system.

    Is there any way of confirming that I can add a change which gets hit? It's on the development server, so I don't need to worry about temporarily breaking anything.



  • @jinpa is there something that says you can't just add a logging call (even the brain-dead version described below) to the code?

    import datetime
    
    with open(logfile,'w') as ofile:
      ofile.write("code got hit at {}".format(datetime.date.today()))
    

  • area_pol

    @Benjamin-Hall said in Proving that my python changes are being hit:

    a logging call

    @jinpa In that case use the logging module.

    import logging        
    log = logging.getLogger('myscript')
    log.setLevel(logging.DEBUG)
    # if you want to write to stdout:
    log.addHandler(logging.StreamHandler()) 
    # if you want to write to file (can be both stdout and file):
    log.addHandler(logging.FileHandler('some_file.log')) 
    # if you want the date in the log entry:
    for h in log.handlers: h.setFormatter(logging.Formatter(fmt='{asctime} | {message}', style='{'))
    
    
    # output to logs:
    def my_func():
    	log.info('hello log')  
    
    


  • @Benjamin-Hall said in Proving that my python changes are being hit:

    @jinpa is there something that says you can't just add a logging call (even the brain-dead version described below) to the code?

    import datetime
    
    with open(logfile,'w') as ofile:
      ofile.write("code got hit at {}".format(datetime.date.today()))
    

    Sorry for the delay. The problem is/was that the scripts as they're being run (not if specifically executed by me) do not have the ability to log to files. However, I've spoken to a devop, and he thinks he can make it so that the scripts do have logging capabilities, which would solve the problem. Unfortunately, he's out sick today, so I'm treading water until he returns.


  • Notification Spam Recipient

    @jinpa said in Proving that my python changes are being hit:

    I'm treading water

    So today is leg day?


Log in to reply