Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Scraping Data From the Web Additional Scraping Tasks Using Scrapers for Site Testing

AttributeError occurs only in Jupyter

Hi. Any idea what causes this to work fine in my console but fail in Jupyter Notebooks?

my code

from urllib.request import urlopen
from bs4 import BeautifulSoup

import unittest

class TestHorseLand(unittest.TestCase):
    soup = None

    def setUpClass():
        url = 'https://github.com/treehouse-projects/horse-land/index.html'

        TestHorseLand.soup = BeautifulSoup(urlopen(url), 'html.parser')

        def test_header1(self):
            header1 = TestHorseLand.soup.find('h1').get_text()
            self.assertEqual('Horse Land', header1)

if __name__ == '__main__':
    unittest.main()

Error I see

E
======================================================================
ERROR: /run/user/1001/jupyter/kernel-f40f8998-b6f3-4dc3-b1f6-c533c177540e (unittest.loader._FailedTest)
----------------------------------------------------------------------
AttributeError: module '__main__' has no attribute '/run/user/1001/jupyter/kernel-f40f8998-b6f3-4dc3-b1f6-c533c177540e'

----------------------------------------------------------------------
Ran 1 test in 0.002s

FAILED (errors=1)
An exception has occurred, use %tb to see the full traceback.

SystemExit: True