assert_raises() from nose.tools won't work rightHow to use nose's assert_raises?How to randomly select an item from a list?How do I remove an element from a list by index in Python?How do you read from stdin?Why can't Python parse this JSON data?Why is reading lines from stdin much slower in C++ than Python?How to remove a key from a Python dictionary?Scipy autotest finished with one errorsomething errors were thrown out when I was testing the scikit-learn with nosetestsHow to use a python function from another moduleSkeleton Directory: Why does script fail when nosetests returns no errors?

Taxes on Dividends in a Roth IRA

I found an audio circuit and I built it just fine, but I find it a bit too quiet. How do I amplify the output so that it is a bit louder?

Review your own paper in Mathematics

Does "he squandered his car on drink" sound natural?

Change the color of a single dot in `ddot` symbol

Creating two special characters

How can ping know if my host is down

Delete multiple columns using awk or sed

Mimic lecturing on blackboard, facing audience

How to explain what's wrong with this application of the chain rule?

What (the heck) is a Super Worm Equinox Moon?

What does Apple's new App Store requirement mean

Shouldn’t conservatives embrace universal basic income?

How much theory knowledge is actually used while playing?

Multiplicative persistence

Is this toilet slogan correct usage of the English language?

Why Shazam when there is already Superman?

Why do Radio Buttons not fill the entire outer circle?

It grows, but water kills it

Why is so much work done on numerical verification of the Riemann Hypothesis?

Does an advisor owe his/her student anything? Will an advisor keep a PhD student only out of pity?

What features enable the Su-25 Frogfoot to operate with such a wide variety of fuels?

Why do ¬, ∀ and ∃ have the same precedence?

Were Persian-Median kings illiterate?



assert_raises() from nose.tools won't work right


How to use nose's assert_raises?How to randomly select an item from a list?How do I remove an element from a list by index in Python?How do you read from stdin?Why can't Python parse this JSON data?Why is reading lines from stdin much slower in C++ than Python?How to remove a key from a Python dictionary?Scipy autotest finished with one errorsomething errors were thrown out when I was testing the scikit-learn with nosetestsHow to use a python function from another moduleSkeleton Directory: Why does script fail when nosetests returns no errors?













0















I'm halfway through the book Learn Python the Hard Way by Zed Shaw. The book doesn't have any coverage or documentation for the function assert_raises().



So I tried to run this test:



from nose.tools import *
from ex48.parser import *

def test_except():
raw_sentence = [('stop', 'the'), ('noun', 'bear'), ('verb', 'kill')]
assert_raises(ParserError, parse_sentence(raw_sentence))


Here's the error when I tried to run nosetests:



======================================================================
ERROR: tests.parser_tests.test_except
----------------------------------------------------------------------
Traceback (most recent call last):
File "####/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "####/ex48/tests/parser_tests.py", line 8, in test_except
assert_raises(ParserError, parse_sentence(raw_sentence))
File "####/ex48/ex48/parser.py", line 69, in parse_sentence
obj = parse_object(word_list)
File "####/ex48/ex48/parser.py", line 53, in parse_object
raise ParserError("Expected a noun or direction next.")
ParserError: Expected a noun or direction next.

----------------------------------------------------------------------
Ran 8 tests in 0.008s

FAILED (errors=1)


Here is where the exception is coming from:



def parse_verb(word_list):
skip(word_list, 'stop')

if peek(word_list) == 'verb':
return match(word_list, 'verb')
else:
raise ParserError("Expected a verb next.")


The call to parse_sentence(raw_sentence) is expected to fail. The assert_raises() should work properly, but it doesn't catch the raised exception from parse_verb() yielding a failed test. What do you think is/are the problem/s?










share|improve this question


























    0















    I'm halfway through the book Learn Python the Hard Way by Zed Shaw. The book doesn't have any coverage or documentation for the function assert_raises().



    So I tried to run this test:



    from nose.tools import *
    from ex48.parser import *

    def test_except():
    raw_sentence = [('stop', 'the'), ('noun', 'bear'), ('verb', 'kill')]
    assert_raises(ParserError, parse_sentence(raw_sentence))


    Here's the error when I tried to run nosetests:



    ======================================================================
    ERROR: tests.parser_tests.test_except
    ----------------------------------------------------------------------
    Traceback (most recent call last):
    File "####/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
    File "####/ex48/tests/parser_tests.py", line 8, in test_except
    assert_raises(ParserError, parse_sentence(raw_sentence))
    File "####/ex48/ex48/parser.py", line 69, in parse_sentence
    obj = parse_object(word_list)
    File "####/ex48/ex48/parser.py", line 53, in parse_object
    raise ParserError("Expected a noun or direction next.")
    ParserError: Expected a noun or direction next.

    ----------------------------------------------------------------------
    Ran 8 tests in 0.008s

    FAILED (errors=1)


    Here is where the exception is coming from:



    def parse_verb(word_list):
    skip(word_list, 'stop')

    if peek(word_list) == 'verb':
    return match(word_list, 'verb')
    else:
    raise ParserError("Expected a verb next.")


    The call to parse_sentence(raw_sentence) is expected to fail. The assert_raises() should work properly, but it doesn't catch the raised exception from parse_verb() yielding a failed test. What do you think is/are the problem/s?










    share|improve this question
























      0












      0








      0








      I'm halfway through the book Learn Python the Hard Way by Zed Shaw. The book doesn't have any coverage or documentation for the function assert_raises().



      So I tried to run this test:



      from nose.tools import *
      from ex48.parser import *

      def test_except():
      raw_sentence = [('stop', 'the'), ('noun', 'bear'), ('verb', 'kill')]
      assert_raises(ParserError, parse_sentence(raw_sentence))


      Here's the error when I tried to run nosetests:



      ======================================================================
      ERROR: tests.parser_tests.test_except
      ----------------------------------------------------------------------
      Traceback (most recent call last):
      File "####/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
      self.test(*self.arg)
      File "####/ex48/tests/parser_tests.py", line 8, in test_except
      assert_raises(ParserError, parse_sentence(raw_sentence))
      File "####/ex48/ex48/parser.py", line 69, in parse_sentence
      obj = parse_object(word_list)
      File "####/ex48/ex48/parser.py", line 53, in parse_object
      raise ParserError("Expected a noun or direction next.")
      ParserError: Expected a noun or direction next.

      ----------------------------------------------------------------------
      Ran 8 tests in 0.008s

      FAILED (errors=1)


      Here is where the exception is coming from:



      def parse_verb(word_list):
      skip(word_list, 'stop')

      if peek(word_list) == 'verb':
      return match(word_list, 'verb')
      else:
      raise ParserError("Expected a verb next.")


      The call to parse_sentence(raw_sentence) is expected to fail. The assert_raises() should work properly, but it doesn't catch the raised exception from parse_verb() yielding a failed test. What do you think is/are the problem/s?










      share|improve this question














      I'm halfway through the book Learn Python the Hard Way by Zed Shaw. The book doesn't have any coverage or documentation for the function assert_raises().



      So I tried to run this test:



      from nose.tools import *
      from ex48.parser import *

      def test_except():
      raw_sentence = [('stop', 'the'), ('noun', 'bear'), ('verb', 'kill')]
      assert_raises(ParserError, parse_sentence(raw_sentence))


      Here's the error when I tried to run nosetests:



      ======================================================================
      ERROR: tests.parser_tests.test_except
      ----------------------------------------------------------------------
      Traceback (most recent call last):
      File "####/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
      self.test(*self.arg)
      File "####/ex48/tests/parser_tests.py", line 8, in test_except
      assert_raises(ParserError, parse_sentence(raw_sentence))
      File "####/ex48/ex48/parser.py", line 69, in parse_sentence
      obj = parse_object(word_list)
      File "####/ex48/ex48/parser.py", line 53, in parse_object
      raise ParserError("Expected a noun or direction next.")
      ParserError: Expected a noun or direction next.

      ----------------------------------------------------------------------
      Ran 8 tests in 0.008s

      FAILED (errors=1)


      Here is where the exception is coming from:



      def parse_verb(word_list):
      skip(word_list, 'stop')

      if peek(word_list) == 'verb':
      return match(word_list, 'verb')
      else:
      raise ParserError("Expected a verb next.")


      The call to parse_sentence(raw_sentence) is expected to fail. The assert_raises() should work properly, but it doesn't catch the raised exception from parse_verb() yielding a failed test. What do you think is/are the problem/s?







      python python-2.7






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked May 21 '17 at 7:04









      Bruce JimenezBruce Jimenez

      32




      32






















          2 Answers
          2






          active

          oldest

          votes


















          0














          Do not call parse_sentence() directly. Instead, pass it as an argument.



          assert_raises(ParserError, parse_sentence, raw_sentence)


          Even better, use assert_raises() in a with block. See How to use nose's assert_raises?






          share|improve this answer
































            0














            This will work



            assert_raises(ParserError, parse_verb, raw_sentence) 





            share|improve this answer
























              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44094078%2fassert-raises-from-nose-tools-wont-work-right%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              Do not call parse_sentence() directly. Instead, pass it as an argument.



              assert_raises(ParserError, parse_sentence, raw_sentence)


              Even better, use assert_raises() in a with block. See How to use nose's assert_raises?






              share|improve this answer





























                0














                Do not call parse_sentence() directly. Instead, pass it as an argument.



                assert_raises(ParserError, parse_sentence, raw_sentence)


                Even better, use assert_raises() in a with block. See How to use nose's assert_raises?






                share|improve this answer



























                  0












                  0








                  0







                  Do not call parse_sentence() directly. Instead, pass it as an argument.



                  assert_raises(ParserError, parse_sentence, raw_sentence)


                  Even better, use assert_raises() in a with block. See How to use nose's assert_raises?






                  share|improve this answer















                  Do not call parse_sentence() directly. Instead, pass it as an argument.



                  assert_raises(ParserError, parse_sentence, raw_sentence)


                  Even better, use assert_raises() in a with block. See How to use nose's assert_raises?







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited May 23 '17 at 11:33









                  Community

                  11




                  11










                  answered May 21 '17 at 7:16









                  Jim KJim K

                  7,73111033




                  7,73111033























                      0














                      This will work



                      assert_raises(ParserError, parse_verb, raw_sentence) 





                      share|improve this answer





























                        0














                        This will work



                        assert_raises(ParserError, parse_verb, raw_sentence) 





                        share|improve this answer



























                          0












                          0








                          0







                          This will work



                          assert_raises(ParserError, parse_verb, raw_sentence) 





                          share|improve this answer















                          This will work



                          assert_raises(ParserError, parse_verb, raw_sentence) 






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Mar 8 at 1:13









                          Trent

                          1,5392036




                          1,5392036










                          answered Mar 8 at 0:02









                          Kaushik PalKaushik Pal

                          1




                          1



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44094078%2fassert-raises-from-nose-tools-wont-work-right%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

                              Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                              2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived