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

Convert tests to pytest #25

Merged
merged 11 commits into from
Jun 12, 2023
Merged

Convert tests to pytest #25

merged 11 commits into from
Jun 12, 2023

Conversation

rebkwok
Copy link
Contributor

@rebkwok rebkwok commented May 16, 2023

Now that we have a python venv available, convert the bash tests to pytest

Copy link
Member

@bloodearnest bloodearnest left a comment

Choose a reason for hiding this comment

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

Thanks for this.

Left a bunch of nits suggestions, if you're inclined :)

output_file.unlink()


@pytest.fixture(autouse=True)
Copy link
Member

Choose a reason for hiding this comment

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

nit: I think scope="session" is more efficient than autouse=True for this kind of fixture, as it will just run (and fail) once, rather than every test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 although it needs scope=session as well as autouse=True, not instead of, otherwise it has to be explicitly included for every test

def run_docker():
def _run(command):
filestem = Path(command.split()[0]).stem
user = subprocess.check_output(
Copy link
Member

Choose a reason for hiding this comment

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

python can do this :)

import os, pwd
uid = os.getuid()
gid = pwd.getpwuid(uid).pw_gid

process = subprocess.run(
f"docker run --rm --user {user} -e STATA_LICENSE -v {TESTS_PATH.resolve()}:/workspace "
f"{IMAGE} {command}",
shell=True,
Copy link
Member

Choose a reason for hiding this comment

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

nit: I prefer cmd lists and not setting shell=True (which can often trip linting errors), but this is a test so its probably fine, and just my OCD :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to do this and couldn't get it to work, but I've just realised why (the command in some tests is a string with spaces and needed split)


@pytest.fixture()
def setup_arrow_files():
for filep in (TESTS_PATH / "fixtures").glob("*.arrow"):
Copy link
Member

Choose a reason for hiding this comment

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

nit: reusing the same fixed test dir, and not deleting them, seems like it might cause issues down the line? But we're not writing any files in the tests, so I guess it doesn't matter

Why to they have to be in the output subdir? Could we just load them from the fixtures subdir?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel like I had a reason once, but now I've no idea what it was. Possibly I thought when I wrote the initial bash test that we didn't have access to the fixtures folder in the container, but we do. I may have just been following the gz test .do file, which loads from the output folder, but that's because it depends on a previous test that generates a file in there.



@pytest.fixture
def run_docker():
Copy link
Member

Choose a reason for hiding this comment

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

nit: s/run_docker/run_stata? Seems to match what it does a bit more?

Copy link
Member

Choose a reason for hiding this comment

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

nit: I don't think run_docker needs to be a pytest fixture, it could just be a test helper?

@rebkwok rebkwok merged commit 0af4528 into main Jun 12, 2023
@rebkwok rebkwok deleted the pytest branch June 12, 2023 09:24
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.

2 participants