Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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, but I think the point of the tests is to actually ensure that the unblocking can be used manually, without requesting the
db
fixture / using the mark, which basically only triggers the unblocking for the test outside already.It might be a good case for the pytest issue maybe, if you/we can figure out what is happening here maybe?
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.
@blueyed Ah, my mistake. I didn't realize. I'll dig into it and see what I can find
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.
@blueyed I think I've figured it out. Try running
Test_django_db_blocker.test_unblock_manually
on its own on pytest 5.3.2 so my changes aren't included. One would expect the test to pass.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.
If it fails, it's because it's not actually setting up the DB.
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.
@SalmonMode
That fails with "django.db.utils.OperationalError: unable to open database file" for me, since it tries to access the "'/should_never_be_accessed'" DB (initial setting, adjusted when setting up the DB).
So this is also kind of expected in general - although should not fail in general.
pytest-django itself is used as a plugin etc and tests are rather fragile (and therefore this ("running that test alone") is not surprising).
It is the same with both 5.3.2 and 5.3.3 in that regard, isn't it?
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.
I just looked into why django orders their tests. They say it's because they need to ensure a clean database for every TestCase. The reason they go about it the way they do, is because of limitations with the
unittest.TestCase
fixture system. I'm not sure why they don't put the onus on the test writer to clean up after themselves, but they understandably want good test hygiene.Pytest fixtures have no such limitation, and no such excuse. WIth pytest fixtures, it's easy to provide a fixture that tears itself down accordingly giving each test case a clean starting point.
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.
As for taking out the reordering logic, I think it would be best to have a more graceful departure from it. I would put out a warning that there are potentially hidden problems by relying on test order, and the plugin should discourage the reliance on it. And eventually the logic should be removed.
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.
It's mostly about speed also: transactional_db tests are especially slow (FYI).
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.
That I can understand. I do, however, have a plan for that as well in
pytest-xdist
.https://github.com/SalmonMode/pytest-xdist/tree/set-test-group
I intend to add another hook to allow reordering of "work groups" so that the test writer can dictate which ones to hand off to workers first. So if they have their slow tests in one work group, then can move that to the top of the ordered dict.
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.
Revised solution here: #807