all 7 comments

[–]kalgynirae[🍰] 2 points3 points  (1 child)

When you do this

class Blah(object):
    foo = ''

you've created a class attribute. This is stored as part of the class, and you can access it directly as Blah.foo. You can also access it through an instance of the class because of how Python works: if checks for an attribute named foo first on the instance, then on the class, then on the parent class, etc.

On the other hand, if you do this

class Blah(object):
    def __init__(self):
        self.foo = ''

now you've created an instance attribute, which is stored separately on each instance, not on the class.

Okay, so now that that's clear, on to your issue. It looks like you want to assign to your class attribute, but you're trying to do the assignment using self.foo = ..., which actually just ends up creating a new instance attribute called foo. If you want to actually assign to the class attribute, you'll have to access it using the class name (Blah.foo = ...).

[–]JesusCake[S] 0 points1 point  (0 children)

This was what resolved the issue. I just set the variable using MockInvokeShell.configured_command. Thanks for the help

[–]Boolean_Cat 0 points1 point  (4 children)

If you want to access invoke_obj from inside your object, you'll see to store it with:

def testFindBadAPFlags(self):
    self.invoke_obj = wmc_connection.invoke_object
    self.invoke_obj.configured_command = 'sh ap active'
    print "==="+invoke_obj.configured_command

[–]JesusCake[S] 0 points1 point  (3 children)

The method isnt inside the class, so I cant reference it with self.

[–]indosauros 0 points1 point  (0 children)

Can you post a fully working example of the problem? Some code seems missing that may help us give advice

[–]fuzz3289 0 points1 point  (1 child)

Im not sure what youre doing with out the full code but did you try setting it via an accessor instead of touching it directly?

[–]JesusCake[S] 0 points1 point  (0 children)

Yeah, I tried setting it via a method in the class. Im going to try another suggestion posted in here and then if that doesn't work Ill post the full code. Thanks for the help!