Skip to content

Setup reporting for missing CSS file #390

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

Merged
merged 3 commits into from
Dec 9, 2020

Conversation

FirePing32
Copy link
Contributor

fixes: #388

Returns missing CSS files in OSError according to the order they were passed.

Copy link
Member

@gnikonorov gnikonorov 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 raising this @prakhargurunani!

Can you please also add:

@gnikonorov gnikonorov added the bug This issue/PR relates to a bug. label Nov 29, 2020
@FirePing32
Copy link
Contributor Author

@gnikonorov I have only changed the way of reporting the missing CSS files. I can't see any new test cases for this change. If any, Please let me know.

@gnikonorov
Copy link
Member

@gnikonorov I have only changed the way of reporting the missing CSS files. I can't see any new test cases for this change. If any, Please let me know.

In the run method you can pass a variable list of arguments via *args. You could pass a list of css files that don't exist and confirm behavior via the css flag

@FirePing32
Copy link
Contributor Author

Thanks @gnikonorov !

@FirePing32
Copy link
Contributor Author

In the run method you can pass a variable list of arguments via *args. You could pass a list of css files that don't exist and confirm behavior via the css flag

@gnikonorov Done.

BeyondEvil
BeyondEvil previously approved these changes Nov 30, 2020
Copy link
Contributor

@BeyondEvil BeyondEvil 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 @prakhargurunani !

I'm satisfied but I'll let @gnikonorov have the last word (and/or merge). 👍

Copy link
Member

@gnikonorov gnikonorov left a comment

Choose a reason for hiding this comment

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

One last comment and then I think this is good to merge @prakhargurunani

assert "No such file or directory: 'style.css'" in result.stderr.str()
assert "Missing CSS file: style.css" in result.stderr.str()

def test_multiple_css_files(self, testdir, recwarn):
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a test for where only part of the passed files are missing? You can use https://github.com/pytest-dev/pytest-html/blob/master/testing/test_pytest_html.py#L321 as an example for creating adhoc files in tests.

Also, please use @pytest.mark.parametrize to combine your tests with the test above. It'll be a lot cleaner than having 2-3 separate tests for the same feature ( reporting of missing css files )

Here is an example of how we parametrize in this file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gnikonorov See 8ccc104
Have I used @pytest.mark.parametrize correctly ?

Copy link
Member

Choose a reason for hiding this comment

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

Almost @prakhargurunani! Please see my last review

assert len(recwarn) == 0
assert expected in result.stderr.str()

def test_some_css_files(self, testdir, recwarn):
Copy link
Member

Choose a reason for hiding this comment

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

You can merge this test with the test above, just create the valid css file in the body of the test.

("abc.css", "xyz.css", "Missing CSS files: abc.css, xyz.css"),
],
)
def test_css_invalid(self, testdir, recwarn, file1, file2, expected):
Copy link
Member

Choose a reason for hiding this comment

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

This is correct, but you could make it even more clean by parametrizing with a list of files instead of passing file1 and file2. For example:

$ cat test_parametrize.py
import pytest

@pytest.mark.parametrize("arg", ["arg1", "arg2", ["arg3.a", "arg3.b"]])
def test_list(arg):
     assert arg is not None
$

In the example above the test is run 3 times. First with "arg1", then "arg2", and finally with the list ["arg3.a", "arg3.b"]

This way your test can be expanded on in the future without changing its signature every time, and it becomes easier to reason about

@FirePing32 FirePing32 requested a review from gnikonorov December 3, 2020 05:48
@gnikonorov
Copy link
Member

I'll take a look tonight @prakhargurunani! Sorry, I've been busy

Copy link
Member

@gnikonorov gnikonorov left a comment

Choose a reason for hiding this comment

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

Please fix the changelog. After that I'm fine with approving

@FirePing32 FirePing32 requested a review from gnikonorov December 5, 2020 17:19
],
)
def test_css_invalid(self, testdir, recwarn, files):
assert files is not None
Copy link
Member

Choose a reason for hiding this comment

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

Is this debug code? files should never be None based on your parametrization

assert result.ret
assert len(recwarn) == 0
assert "No such file or directory: 'style.css'" in result.stderr.str()
if isinstance(files, list):
assert files[0], files[1] in result.stderr.str()
Copy link
Member

Choose a reason for hiding this comment

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

Sorry I missed this, but this doesn't do what you expect. You aren't actually checking for files[0]. This just checks whether or not files[0] is truthy and executes files[1] in result.stderr.str() if it's not. For example:

>>> l = [1,2,3]
>>> assert 0, 2 in l
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AssertionError: True
>>> assert 44, 2 in l

@FirePing32 FirePing32 requested a review from gnikonorov December 6, 2020 05:38
gnikonorov
gnikonorov previously approved these changes Dec 6, 2020
Copy link
Member

@gnikonorov gnikonorov left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @prakhargurunani !

I'll leave the final review/merge up to @BeyondEvil

@FirePing32 FirePing32 requested a review from BeyondEvil December 6, 2020 15:51
BeyondEvil
BeyondEvil previously approved these changes Dec 9, 2020
Copy link
Contributor

@BeyondEvil BeyondEvil 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 all the hard work @prakhargurunani !

This looks great!

Can you squash and rebase so we can merge?

@BeyondEvil
Copy link
Contributor

@gnikonorov docs are failing, not sure what to do here? 🤔

@FirePing32 FirePing32 dismissed stale reviews from BeyondEvil and gnikonorov via 4086b9e December 9, 2020 12:21
@gnikonorov
Copy link
Member

@BeyondEvil docs are failing because the RTD build was enabled before the PR for RTD was merged. Once #402 goes in the issue will go away

Copy link
Contributor

@BeyondEvil BeyondEvil left a comment

Choose a reason for hiding this comment

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

Thanks everyone!

@BeyondEvil BeyondEvil merged commit 8b7bdc1 into pytest-dev:master Dec 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Not all missing CSS files are reported
3 participants