Q: Python decorator: run decorator before test I'm looking to add a decorator that runs a video recorder on certain tests like so:
@decorators.video(self)
def test_1234(self):
    ...

I'm having trouble passing the self variable into the decorator as it is need for some attributes. How can I do this?

A: theodox answer is generally good, but for decorators you should use functools.wraps function, like in an example below:
from functools import wraps

def enable_video(fn)
    '''Decorate the function to start video, call the function, stop video.'''
    @wraps(fn)
    def inner(*args, **kwargs): 
    # could be just `def inner(self):` if only intended to use
    # with methods without arguments and keyword arguments
        do_stuff_before()
        fn(*args, **kwargs)
        do_stuff_after()
    return inner

It will persist original docstrings, original function name (and more). You can read more about it in Python docs.
Then, assuming that previous code is in decorators module, you should use it as follows:
class MyTestCase(unittests.TestCase);
    @decorators.enable_video
    def testSomeVideoFunction(self):
        do_test_stuff()

Note that in the code example it's just @decorators.enable_video, not @decorators.enable_video(self). As like in jonrsharpe's comment to your question, reference to a self is not present at a decoration time.

A: Are you sure you need the self reference at all?  
More commonly you'd do something like this
def enable_video(fn):
    '''decorate the test function so it starts the video, runs the test, and stop the video'''   
    def video_aware_test(self_refrence):
       start_video_recorder()
       try:
          fn()
       finally:
          stop_video_recorder()
    return video_aware_test

And you'd apply it like this:
 @enable_video
 def test_something(self)

If for some reason the decorator actually needed the self reference, you can see where you'd grab it.  This version doesn't include configuring the video recorder in any way, to that you'd use a class rather than a function decorator and pass the configuration as arguments.
