I have a test class to test my methods but i have some issue with passing self, both of them are inside class and test class.
my method:
def get_all_links(self):
"""return all the links inside an html
:return: list of links from an html page
:rtype: list
"""
return self.html.find_all('a')
my test case:
@parameterized.expand(["http://www.google.com", "http://www.walla.com"])
def test_get_all_links_known_links(self, known_link):
"""check get_all_links with a known link list
:param known_link: lick to find
:type known_link: str
"""
html = Parser(open(os.path.normpath(os.path.join(self.root, "test.html"))))
self.assertTrue(any([known_link in str(l) for l in html.get_all_links()]))
error:
E TypeError: test_get_all_links_known_links() takes exactly 2 arguments (1 given)
/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/case.py:329: TypeError
...
You really don't need to subclass unittest.TestCase
here:
You can also "parametize" tests using pytest as well:
Example:
import pytest
from app.objects import Root # Example
known_links = [
"http://www.google.com",
"http://www.walla.com"
]
@pytest.fixture()
def root(request):
return Root() # Root object
@pytest.mark.parametrize("known_links", known_links)
def test_get_all_links_known_links(root, known_link):
html = Parser(
open(os.path.normpath(os.path.join(root, "test.html")))
)
assert any([known_link in str(l) for l in html.get_all_links()])
See:
You need to import parameterized
before using the decorator:
from nose_parameterized import parameterized
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With