-
-
Notifications
You must be signed in to change notification settings - Fork 653
Fix some bugs in conftest.py
, one in _destroy_dist_context
and the other in distributed
#2788
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
Fix some bugs in conftest.py
, one in _destroy_dist_context
and the other in distributed
#2788
Conversation
@sadra-barikbin do you think it would make sense and can help if we were using a class with fixture, something like @pytest.mark.usefixtures("cleandir")
class TestDirectoryInit:
def test_cwd_starts_empty(self):
assert os.listdir(os.getcwd()) == []
with open("myfile", "w") as f:
f.write("hello")
def test_cwd_again_starts_empty(self):
assert os.listdir(os.getcwd()) == [] (in this example fixture is called for each function, but maybe there is a way to set it up once per class) |
97a68aa
to
63a62a3
Compare
conftest.py
, one in _destroy_dist_context
and the other in distributed
conftest.py
, one in _destroy_dist_context
and the other in distributed
Yes we could and it helps. Teardown takes place exactly after the last test of the class: import pytest
@pytest.fixture(scope="class", params=[1, 2])
def cls_fixt(request):
param = request.param
print(" SETUP cls_fixt", param)
yield param
print(" TEARDOWN cls_fixt", param)
@pytest.fixture(scope="function", params=[1, 2])
def fun_fixt(request):
param = request.param
print(" SETUP fun_fixt", param)
yield param
print(" TEARDOWN fun_fixt", param)
@pytest.mark.usefixtures("cls_fixt")
class Test2:
def test_1(self):
print("hello")
def test_4(self, fun_fixt):
print("world")
def test_2():
print("hi")
def test_3(fun_fixt):
print("there!") By the way, current behavior of |
In pytest they've considered this behavior, an inefficiency: |
63a62a3
to
22692c1
Compare
22692c1
to
f1670ee
Compare
The latest change that I introduced to distributed fixture is due to an error that came up when I removed |
@sadra-barikbin CI is still failing somehow |
ef7dd05
to
c54baf7
Compare
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 @sadra-barikbin , lgtm !
Won't you merge it? |
Description:
distributed
fixture tomodule
so as to have just one distributed setup and teardown for all distributed tests in a module but this caused some non-distributed tests to fail. It turned out that the teardown of the last instance of the fixture (we have an instance fornccl
, one forgloo
, one forgloo_cpu
and...) takes place after running the last test of the module, even if it has not requested the fixture. Running the snippet below which is originally from pytest website shows this fact:Output:

So I changed the scope of the fixture from
module
tofunction
to solve the issue.