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

Converting tests to pytests discovers duplicated test code #21

Closed
eumiro opened this issue Jan 11, 2021 · 12 comments
Closed

Converting tests to pytests discovers duplicated test code #21

eumiro opened this issue Jan 11, 2021 · 12 comments
Assignees

Comments

@eumiro
Copy link
Member

eumiro commented Jan 11, 2021

During the attempt to convert the test suite to PyTest, I have discovered, that the two tests:

  • test_10_passing_file_object
  • test_20_passing_filename

from

def test_10_passing_file_object(self):
text = b"Hello World!\n"
with TemporaryFile() as fileobj:
fileobj.write(text)
fileobj.flush()
archive = ArchiveFile(fileobj=fileobj)
self._regular_tests(archive, fileobj, fileobj.name, text)
def test_20_passing_filename(self):
text = b"Hello World!\n"
with TemporaryFile() as fileobj:
fileobj.write(text)
fileobj.flush()
archive = ArchiveFile(fileobj=fileobj)
self._regular_tests(archive, fileobj, fileobj.name, text)

were identical. What should be the difference between them, @cecton ?

@cecton
Copy link
Collaborator

cecton commented Jan 11, 2021

It's been years for me haha 😅

Looking at the function name I guess the 2 tests are identical except for how they pass the file argument to the destream class. Probably at some point one was using a filename instead of a file object. It has to work for both (if that still exists in the API).

But don't take my word for it, try to use git blame on the file and see if they ever were different.

@jruere
Copy link
Contributor

jruere commented Jan 12, 2021

Why convert to pytest at all?

@eumiro
Copy link
Member Author

eumiro commented Jan 12, 2021

The syntax with assert instead of self.assert* is nicer and more intuitive, the fixtures and parametrization makes the code more readable.

And it looks like touching the whole test codebase could show up some issues like this one :-)

@cecton
Copy link
Collaborator

cecton commented Jan 12, 2021

I do prefer py.test too! I'm not sure it even existed when this project started.

Overall it's a nice improvement as it is easier to get in the code.

@eumiro
Copy link
Member Author

eumiro commented Jan 12, 2021

And in the meantime it even dropped the dot from py.test to pytest. Okay, let me see what we can do. :-)

@eumiro
Copy link
Member Author

eumiro commented Jan 12, 2021

But first, #22 needs to be reviewed/approved/merged.

@jruere
Copy link
Contributor

jruere commented Jan 12, 2021

Fair enough!

@eumiro
Copy link
Member Author

eumiro commented Jan 17, 2021

Why didn't this get closed with #27?

@eumiro eumiro closed this as completed Jan 17, 2021
@cecton
Copy link
Collaborator

cecton commented Jan 17, 2021

It's because you need to write "Closes #21 " or "Fixes #21" in the commit message

@eumiro
Copy link
Member Author

eumiro commented Jan 18, 2021

Does it have to be a commit message? I remember closing issues with PR messages like this one from our PR that I expected to close this issue:
#27 (comment)

@cecton
Copy link
Collaborator

cecton commented Jan 18, 2021

Pretty sure (80%) it has to be in the commit message or the title of the commit (which is actually part of the message).

Some words also don't close the linked issue. For instance: "Related #21" will link but not close when the PR gets merged.

@eumiro
Copy link
Member Author

eumiro commented Jan 18, 2021

Found it: in the PR number 19 I wrote Closes and the number 17 into the PR message. It even highlighted the word Closes. So maybe this has to be in the initial message (description) of a PR and not in a comment. 🤷

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

No branches or pull requests

3 participants