Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Raise Exception: 'NoneType' object has no attribute 'get' #761

Answered by mdmintz
iqbalshekh asked this question in Q&A
Discussion options

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.

You must be logged in to vote

@iqbalshekh
Eight things:

  1. Needs indentation
  2. Spelling of except Exception
  3. Missing : at the end of the except Exception line
  4. Missing : at the end of the if line
  5. Need to use an actual URL in the self.get() line
  6. Check for equality should be ==, not =
  7. The name/main line should be if __name__ == "__main__" :
    But most importantly:
  8. You have to run the script using pytest. (So don't use if __name__ == "__main__" :)

Replies: 2 comments 1 reply

Comment options

@iqbalshekh
Eight things:

  1. Needs indentation
  2. Spelling of except Exception
  3. Missing : at the end of the except Exception line
  4. Missing : at the end of the if line
  5. Need to use an actual URL in the self.get() line
  6. Check for equality should be ==, not =
  7. The name/main line should be if __name__ == "__main__" :
    But most importantly:
  8. You have to run the script using pytest. (So don't use if __name__ == "__main__" :)
You must be logged in to vote
1 reply
Comment options

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,

Answer selected by mdmintz
Comment options

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.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /