Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: replace nosetests with pytest #936

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jaredkhan
Copy link
Collaborator

@jaredkhan jaredkhan commented Jan 18, 2025

Work in progress. Will probably need some input from @lentinj and @hyanwong because it looks like these tests haven't been run for a good while and there's lots to fix.

You can still use grunt exec:test_server_functional or python -m pytest tests/functional to run the tests
About half of them fail at the moment

@@ -1807,7 +1807,7 @@ def licence():
return dict()

def news():
redirect(URL('default', 'milestones.html'))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was redirecting to a non-existent page

import os.path

class TestViewerLoading(FunctionalTest):
"""
Test whether the viewer loading functions work
"""
@classmethod
def setUpClass(self):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spelling of setup/teardown stuff changes across the board


To carry out tests on a remote machine, you can specify a [url][server] and [url][port]
in a config file, which will not give the FunctionalTest class an is_local attribute
and hence will skip tests marked @attr('is_local'). E.g. for testing beta.onezoom.org, you can do

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll want to choose a solution for running the functional tests on beta.onezoom.org, though it doesn't have to look like this

@@ -97,55 +93,50 @@ def striptext_in_file(line, file):
selenium_logger.setLevel(logging.WARNING)
#chrome_options = webdriver.ChromeOptions()
#chrome_options.add_experimental_option("mobileEmulation", { "deviceName": "iPhone 7" })
self.caps = webdriver.ChromeOptions().to_capabilities()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also updated to selenium 4 whilst we're here, so lots of 'find_element_by...' stuff has changed to the new interface

print(">> removing temporary appconfig")
os.remove(self.appconfig_loc)

@tools.nottest
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed some functions so that things we actually want collected as tests start in 'test_' and those that we don't want collected as tests do not

@@ -107,29 +104,7 @@ def test_ott(self, extra_assert_tests, ott, extra_assert_tests_from_another_brow
assert has_linkouts(browser, include_site_internal=True) == False
assert self.zoom_disabled()
print(" ", end="", flush=True)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what this unused function was about. Looks like just an unfinished idea for a test?

@@ -3,16 +3,16 @@
import subprocess
import urllib.request
from time import sleep
#use testconfig from nose (get it using `pip3 install nose-testconfig`)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's where nosetest-testconfig was imported

@@ -47,7 +47,10 @@ def get_db_connection():
pw = getpass("Enter the sql database password: ")
else:
pw = match.group(2)
db['connection'] = pymysql.connect(user=match.group(1), passwd=pw, host=match.group(3), db=match.group(4), port=3306, charset='utf8mb4')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove before merging, just there for debugging

@@ -21,7 +21,7 @@ <h4>Send in your own comments</h4>

<ul class = "uk-list columns blockquote-ul">
{{category_order={'Scientists': 0, 'Lecturers and professors': 1, 'User quotes': 2, 'Professionals': 3, 'Students': 4, 'Educators': 5} }}
{{for category in sorted(quotes.keys(), key=lambda x: category_order.index(x) if x in category_order else len(category_order)):}}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how this is working at all in prod, can anyone enlighten me? @hyanwong? Is there some bygone version of python where dicts have an 'index' method that I don't know about? Is it some web2py shenanigans?

@@ -36,7 +36,7 @@ def test_MD_nolinks(self):
#only get the ones with an id
id = elem.get_attribute("id")
if id:
yield self.MD_nolinks, id
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just doing something simple for now, but could in principle do some fancier fixture stuff here for better reporting

@jaredkhan jaredkhan requested a review from hyanwong January 18, 2025 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant