-
Notifications
You must be signed in to change notification settings - Fork 1.3k
tests: several tests migrated unittest to pytest #7273
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
Conversation
pmrowla
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @nik123
The changes relating to moving from unittest to pytest look good, but a lot of the tests should also be updated to use the tmp_dir/dvc/scm fixtures correctly. Basically, in the old tests there are a lot of places where main() is used, but we can now just use the pytest fixtures instead.
I noticed that you did replace the TestDvc.create() calls with tmp_dir.gen() which is a good start, but in a lot of cases there are more lines that can also be replaced.
For example
tmp_dir.gen("foo", "foo")
ret = main(["add", "foo"])
assert 0 == retcan be replaced with just
tmp_dir.dvc_gen("foo", "foo")
(dvc_gen is tmp_dir.gen() that automatically dvc adds everything as well
I marked a few cases that I noticed during the review, but please double check the tests you've migrated for similar changes that could be made.
tests/func/test_odb.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should no longer be needed with the dvc fixture
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pmrowla - I've removed dvc.__init__ call and main calls in this test. But I had to also add dvc.odb = ODBManager(dvc) because dvc.config updates are not applied to dvc.odb.config. If there is a better way to update odb, please tell me.
tests/func/test_odb.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test should really be re-written to use the tmp_dir fixture properly. It also does not need the scm or dvc fixtures, since the test itself is initializing DVC repos with --no-scm.
So the test should be something like:
def test_shared_cache_dir(tmp_dir):
cache_dir = tmp_dir / "cache"
for d in ["dir1", "dir2"]:
makedirs(tmp_dir / d)
with (tmp_dir / d).chdir():
# do the rest of the test operations
...
assert not (tmp_dir / "dir1" / ".dvc" / "cache").exists()
assert not (tmp_dir / "dir2" / ".dvc" / "cache").exists()
...We can also just use (tmp_dir / d).gen(...) instead of the existing with open(...): write(...) calls as well
@pmrowla I've replaced
|
|
@nik123 thanks for making the changes. I think it looks ok now, could you please squash your commits together? We have started merging rebased/linear history into the main DVC branch (rather than squashing all PRs into single commits). In this case, it should be fine to squash down to a single |
fedca4b to
6de4817
Compare
6de4817 to
73883b8
Compare
@pmrowla Not sure if I understood you right but I've squashed all commits in BTW could you please elaborate why you stopped using squashing? |
That's fine, thanks
Because for larger PR's, it makes sense to merge multiple commits from the PR as separate commits instead of one giant squashed commit. This makes things like doing Basically, for small/straightforward PR's, like this one, we will generally still want to squash them into a single commit, but it's now on the devs to do it selectively when it makes sense, as opposed to always squashing PR into a single commit by default. |
|
Thanks again @nik123 🙏 |
Part of #1819
Changes:
TestGitinbasic_env.py.unittest.TestCasesubclasses infunc/test_odb.pymigrated to pytest:TestCacheLoadBadDirCache,TestExternalCacheDir,TestSharedCacheDir,TestCacheLinkType,TestCmdCacheDirunittest.TestCasesubclasses infunc/test_fs.pymigrated to pytest:TestMtimeAndSize,TestContainsLink,I have followed the checklit.
This PR doesn't require documentation updates.