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

Better code structure for generating pytest plugins #100

Open
MatthewFlamm opened this issue Nov 18, 2021 · 0 comments
Open

Better code structure for generating pytest plugins #100

MatthewFlamm opened this issue Nov 18, 2021 · 0 comments
Labels
help wanted Extra attention is needed

Comments

@MatthewFlamm
Copy link
Owner

The current code is more or less one long script. Some portions should be abstracted out for better understandability and maintainability.

For example, this code is logically separate from the rest (it only needs to know where to find the file for modification):

# modify load_fixture
with open(os.path.join(PACKAGE_DIR, "common.py"), "r") as original_file:
data = original_file.readlines()
import_time_lineno = [i for i, line in enumerate(data) if "from time" in line]
assert len(import_time_lineno) == 1
data.insert(import_time_lineno[0] + 1, "import traceback\n")
load_fixture_lineno = [i for i, line in enumerate(data) if "load_fixture" in line]
assert len(load_fixture_lineno) == 1
data.insert(load_fixture_lineno[0] + 2, " start_path = traceback.extract_stack()[-2].filename\n")
data[load_fixture_lineno[0] + 3] = data[load_fixture_lineno[0] + 3].replace("__file__", "start_path")
with open(os.path.join(PACKAGE_DIR, "common.py"), "w") as new_file:
new_file.writelines(data)

@MatthewFlamm MatthewFlamm added the help wanted Extra attention is needed label Nov 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant