Skip to content

Fix tests for SQLAlchemy 1.4 #104

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
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,24 @@ def test(session, sqlalchemy):
with_coverage = False
else:
with_coverage = True
pytest_cmd = ["pytest"] + (
session.posargs or [
"--pyargs", "sqlalchemy_mptt",
"--cov", "sqlalchemy_mptt", "--cov-report", "term-missing:skip-covered",
"-W", "error:::sqlalchemy_mptt"
if with_coverage:
coverage_options = [
"--cov", "sqlalchemy_mptt",
"--cov-report", "term-missing:skip-covered",
"--cov-report", "xml"
]
) + (["--cov-report", "xml"] if with_coverage else [])
elif session.python.startswith("pypy"):
# Disable coverage for PyPy as it slows down the tests significantly
# See: https://github.com/sqlalchemy/sqlalchemy/issues/9154#issuecomment-1687420057
coverage_options = []
else:
coverage_options = [
"--cov", "sqlalchemy_mptt",
"--cov-report", "term-missing:skip-covered"
]
pytest_cmd = ["pytest"] + coverage_options + (
session.posargs or ["--pyargs", "sqlalchemy_mptt", "-W", "error:::sqlalchemy_mptt"]
)
session.run(*pytest_cmd)


Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SQLAlchemy>=1.0.0,<1.4
SQLAlchemy>=1.0.0,<2.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def read(name):

setup(
name="sqlalchemy_mptt",
version="0.4.0",
version="0.5.0",
url="http://github.com/uralbash/sqlalchemy_mptt/",
author="Svintsov Dmitry",
author_email="sacrud@uralbash.ru",
Expand Down
13 changes: 8 additions & 5 deletions sqlalchemy_mptt/tests/cases/edit_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,11 +478,14 @@ def test_rebuild(self):
4 14(9)15 18(11)19
"""

self.session.query(self.model).update({
self.model.left: 0,
self.model.right: 0,
self.model.level: 0
})
self.session.query(self.model).update(
{
self.model.left: 0,
self.model.right: 0,
self.model.level: 0
},
synchronize_session=False # Fails with the default 'evaluate' option for SQLAlchemy 1.4 on PyPy
)
self.model.rebuild(self.session, 1)
_level = self.model.get_default_level()
self.assertEqual(
Expand Down
4 changes: 3 additions & 1 deletion sqlalchemy_mptt/tests/cases/get_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ def test_get_empty_tree(self):
"""
No rows in database.
"""
self.session.query(self.model).delete()
self.session.query(self.model).delete(
synchronize_session=False # Fails with the default'evaluate' option for SQLAlchemy 1.4 on PyPy
)
self.session.flush()
tree = self.model.get_tree(self.session)
self.assertEqual(tree, [])
Expand Down
12 changes: 5 additions & 7 deletions sqlalchemy_mptt/tests/test_inheritance.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,9 @@ class TestInheritanceTree(TreeTestingMixin, unittest.TestCase):
base = Base2
model = InheritanceTree

# For SQLAlchemy 1.4 support
# @unittest.skipIf(
# sa.__version__ < "1.4",
# "Trees involving inheritance are only supported on "
# "SQLAlchemy version 1.4 and above")
@unittest.expectedFailure
def test_rebuild(self):
@unittest.skipIf(
sa.__version__ < "1.4",
"Trees involving inheritance are only supported on "
"SQLAlchemy version 1.4 and above")
def test_rebuild(self): # pragma: no cover
super(TestInheritanceTree, self).test_rebuild()