Skip to content

Observed AttributeError: 'Tests' object has no attribute 't' again as issue #3869 #5193

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

Closed
vipkum2 opened this issue May 1, 2019 · 13 comments
Labels
type: question general question, might be closed after 2 weeks of inactivity

Comments

@vipkum2
Copy link

vipkum2 commented May 1, 2019

class Tests(object):
    @classmethod
    @pytest.fixture(scope='module', autouse=True)
    def getTestFixture(self, request):
        self.fixtureIp   = request.config.getoption('--fixtureIp')

        # Connect to the NE
        self.t = OpenRoadmTest(self.fixtureIp)


    def test00_getStartingConfig(self):
        print(self.t)

After executing the same observed:

    def test00_getStartingConfig(self):
>       print(self.t)
E       AttributeError: 'Tests' object has no attribute 't'

testWNode_spdr.py:58: AttributeError

Same was working with pytest 3.0.4, python 3.6.3. But now I have upgraded to pytest 4.4.1 and python 3.6.5. I have raised a same issue #3869 but solution written in issue is not working here.

@nicoddemus
Copy link
Member

Hi @vipkum2,

Try this please:

class Tests(object):

    @pytest.fixture(scope='module', autouse=True)
    def getTestFixture(self, request):
        self.fixtureIp   = request.config.getoption('--fixtureIp')

        # Connect to the NE
        self.t = OpenRoadmTest(self.fixtureIp)


    def test00_getStartingConfig(self):
        print(self.t)

(IOW just remove the @classmethod)

If that doesn't work please post a reproducible example.

@nicoddemus nicoddemus added the type: question general question, might be closed after 2 weeks of inactivity label May 1, 2019
@vipkum2
Copy link
Author

vipkum2 commented May 2, 2019

Thanks @nicoddemus to look into this!

Observed same issue without @classmethod also:

==================================================================================================== FAILURES =====================================================================================================
_________________________________________________________________________________________ Tests.test00_getStartingConfig __________________________________________________________________________________________

self = <py3_openroadm.testWNode_spdr.Tests object at 0x7f5050563a20>

    def test00_getStartingConfig(self):
>       print(self.t)
E       AttributeError: 'Tests' object has no attribute 't'

testWNode_spdr.py:57: AttributeError

@nicoddemus
Copy link
Member

That's strange. Can you post a reproducible example? If not, please post the full code.

@nicoddemus
Copy link
Member

Oh I just realized my example missed something: use type(self).t = ... too

@vipkum2
Copy link
Author

vipkum2 commented May 5, 2019

I will paste same tomorrow.

@vipkum2
Copy link
Author

vipkum2 commented May 6, 2019

Now Please take a look:

hax-vipkumar-1|~/scripts$ cat test.py 
import pytest
class Tests(object):
    @classmethod
    @pytest.fixture(scope='module', autouse=True)
    def getTestFixture(self, request):
        self.fixtureIp   = '1.1.1.1' 

        # Connect to the NE
        self.t = 5


    def test00_getStartingConfig(self):
        print(self.t)
hax-vipkumar-1|~/scripts$ 

hax-vipkumar-1|~/scripts$ pt3 -s -v test.py 
=============================================================================================== test session starts ===============================================================================================
platform linux -- Python 3.6.5, pytest-4.4.1, py-1.8.0, pluggy-0.9.0 -- /opt/tools/swtools/anaconda/pftools/envs/linux-64/openroadm_py3/bin/python
cachedir: .pytest_cache
rootdir: /home/vipkumar/scripts
collected 1 item                                                                                                                                                                                                  

test.py::Tests::test00_getStartingConfig FAILED

==================================================================================================== FAILURES =====================================================================================================
_________________________________________________________________________________________ Tests.test00_getStartingConfig __________________________________________________________________________________________

self = <test.Tests object at 0x7f7b9ec04278>

    def test00_getStartingConfig(self):
>       print(self.t)
E       AttributeError: 'Tests' object has no attribute 't'

test.py:13: AttributeError
============================================================================================ 1 failed in 0.05 seconds =============================================================================================

@vipkum2
Copy link
Author

vipkum2 commented May 6, 2019

And as you told, below is working without @classmethod and with type(self).t:
I don't want to change the script accordingly this as these are working scripts.

import pytest
class Tests(object):
    #@classmethod
    @pytest.fixture(scope='module', autouse=True)
    def getTestFixture(self, request):
        self.fixtureIp   = '1.1.1.1'

        # Connect to the NE
        type(self).t = 5


    def test00_getStartingConfig(self):
        print(self.t)
hax-vipkumar-1|~/scripts$ pt3 -s -v test.py 
=============================================================================================== test session starts ===============================================================================================
platform linux -- Python 3.6.5, pytest-4.4.1, py-1.8.0, pluggy-0.9.0 -- /opt/tools/swtools/anaconda/pftools/envs/linux-64/openroadm_py3/bin/python
cachedir: .pytest_cache
rootdir: /home/vipkumar/scripts
collected 1 item                                                                                                                                                                                                  

test.py::Tests::test00_getStartingConfig 5
PASSED

@nicoddemus
Copy link
Member

I don't want to change the script accordingly this as these are working scripts.

I don't understand, you say you don't want to apply the working fix above?

@vipkum2
Copy link
Author

vipkum2 commented May 7, 2019

Actually, These are working with earlier version of pytest, but in latest version, to execute the same scripts I have to change the scripts with your fix.
So my query is - can't we change the same in pytest if possible. Otherwise if there is no option left I have to change all the scripts.

Thank you very much for your time and help !

@RonnyPfannschmidt
Copy link
Member

so this is a regression report?

@nicoddemus
Copy link
Member

So my query is - can't we change the same in pytest if possible. Otherwise if there is no option left I have to change all the scripts.

Oh I see. Unfortunately this is a duplicate of #3778, which unfortunately we won't be able to fix, for the reasons mentioned in that issue and in #3781. 😕

I'm afraid the only solution now is to update your test files.

@vipkum2
Copy link
Author

vipkum2 commented May 8, 2019

Ok thanks @nicoddemus ,

At least we have workaround to run the suites. I will change the scripts accordingly.

Thanks once again to resolving my problem !!!

@vipkum2 vipkum2 closed this as completed May 8, 2019
@vipkum2
Copy link
Author

vipkum2 commented May 8, 2019

Ok thanks @nicoddemus ,

At least we have workaround to run the suites. I will change the scripts accordingly.

Thanks once again to resolving my problem !!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question general question, might be closed after 2 weeks of inactivity
Projects
None yet
Development

No branches or pull requests

3 participants