-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Raise Exception: 'NoneType' object has no attribute 'get' #761
-
test_login.py
class TestLogin(BaseCase):
def setUp(self):
def test_A_LoginPage(self):
try:
self.get("Web URL")
excet exception as e
print(e)
def tearDown(self):
if name="main"
loginobj= TestLogin()
loginobj.test_A_LoginPage()
I have python application project in visual studio and have above file as test_login.py. The problem is This code work properly in command line execution i.e pytest test_login.py but in debug mode above code execution show me below exception
Exception : AttributeError("'NoneType' object has no attribute 'get'")
can you please tell where I am doing wrong.
Beta Was this translation helpful? Give feedback.
All reactions
@iqbalshekh
Eight things:
- Needs indentation
- Spelling of
except Exception
- Missing
:
at the end of theexcept Exception
line - Missing
:
at the end of theif
line - Need to use an actual URL in the
self.get()
line - Check for equality should be
==
, not=
- The name/main line should be
if __name__ == "__main__" :
But most importantly: - You have to run the script using
pytest
. (So don't useif __name__ == "__main__" :
)
Replies: 2 comments 1 reply
-
@iqbalshekh
Eight things:
- Needs indentation
- Spelling of
except Exception
- Missing
:
at the end of theexcept Exception
line - Missing
:
at the end of theif
line - Need to use an actual URL in the
self.get()
line - Check for equality should be
==
, not=
- The name/main line should be
if __name__ == "__main__" :
But most importantly: - You have to run the script using
pytest
. (So don't useif __name__ == "__main__" :
)
Beta Was this translation helpful? Give feedback.
All reactions
-
Hi,
Thanks for the comment.
As I mention this code successfully run using pytest from command prompt and test case is pass. but here my concern is about Debug mode. as while scripting we need to debug the functions\methods so that case it is giving error.
Thanks,
Beta Was this translation helpful? Give feedback.
All reactions
-
To use Debug Mode, drop this into your tests where you want a breakpoint:
import ipdb; ipdb.set_trace()
Commands: h
: Help. c
: Continue. where
: Stacktrace location. u
: Up stack. d
: Down stack. longlist
/ ll
: See code. dir()
: List namespace objects.
You can also trigger Debug Mode on test failures if you add --pdb
to your pytest run command.
Beta Was this translation helpful? Give feedback.