Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow access to parent classes from inner classes #30

Closed
bitprophet opened this issue Apr 13, 2013 · 1 comment
Closed

Allow access to parent classes from inner classes #30

bitprophet opened this issue Apr 13, 2013 · 1 comment

Comments

@bitprophet
Copy link
Owner

Use of naive (and old-style) inner classes as the method for recursive namespacing works reasonably well, but currently makes it impossible to access "parent" class state.

So in this example setup:

class MainSpec(Spec):
    def setup(self):
        self.value1 = 'lol'
        self.value2 = 'wut'

    def top_level_test(self):
        eq_(self.value1, 'lol')

    class method_name:
        def should_whatever(self):
            eq_(self.value2, 'wut')

The method_name.should_whatever test has a distinct self from the MainSpec outer class, and cannot access data set up by that parent class' setup. (So the inner test will fail.)

Would be rad if we could annotate the inner classes with a link to their parent to allow for this, changing the last line above to e.g. eq_(self.parent.value2, 'wut').

@bitprophet
Copy link
Owner Author

Welp, forgot we already do this association for other bookkeeping purposes via _parent.

However, this is on the class objects - so we need a way to go from a handle to a class object, to a setup'd instance. At least in my own usage of Spec/Nose here, I never need any actual state from outside these classes, meaning that a "naive" instantiate-and-call-setup procedure should work reasonably well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant