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
add test for commandline #28
add test for commandline #28
Conversation
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.
Hi Yumei, the logic for your unit test looks good. But it is not being collected or run by pytest since its not part of a function/method.
You'll need to add it to a method instead of directly putting in the class like so.
Also, could you please make a separate file for this class, since the pattern is to have a test
file for every source
file.
In your case, it would be tests/utils/test_commandline.py
.
And the root class name would be TestCommandline
. You can put all your test logic in a method for this class.
hi @Amnish04, thanks for your comments, I've already revise my code, help me view please. |
@WangGithub0 Thanks for the changes. Fixing those should run the tests step. |
@WangGithub0 Hi Yumei, I think the change to I would suggest storing the original state of that system variable before patching it, and then restore that state once you're done with your tests like this. # Save the original sys.argv
original_argv = sys.argv.copy()
# Apply the patch to sys.argv to mimic command-line arguments
with patch.object(sys, "argv", ["commandline.py"] + arguments):
# Create an instance of the CommandlineParser
parser = CommandlineParser()
# Get the parsed arguments
args = parser.get_args()
# Assert that the arguments are correctly parsed
assert args.config == "config.toml"
assert args.input_path == "input.md"
assert args.output == "./dist/til"
assert args.version
# After the block, revert sys.argv to its original state
sys.argv = original_argv |
@WangGithub0 My implementation of CommandlineParser was to only have one instance of the class in a single run. |
@WangGithub0 Just pushed the fix fbd0223 You can pull latest from master |
will the test run again automatically? |
Yes |
@WangGithub0 |
@WangGithub0 Thanks for the contribution! |
write test for src/utils/commandline.py file, coverage from 70%->84%
closes #27