Closed vipkum2 closed 5 years ago
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.
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
That's strange. Can you post a reproducible example? If not, please post the full code.
Oh I just realized my example missed something: use type(self).t = ...
too
I will paste same tomorrow.
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 =============================================================================================
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
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?
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 !
so this is a regression report?
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.
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 !!!
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 !!!
After executing the same observed:
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.