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

Page header does not take environment variables into account #201

Closed
MaximeWeyl opened this issue Apr 25, 2019 · 16 comments · Fixed by #203
Closed

Page header does not take environment variables into account #201

MaximeWeyl opened this issue Apr 25, 2019 · 16 comments · Fixed by #203

Comments

@MaximeWeyl
Copy link

In pytest.ini, I have :

addopts = --html $APPRENTI_MOTEUR_LOGS_DIR_TEST/$APPRENTI_MOTEUR_LOGS_HTML_NAME

The path of the html report takes the content of the environment variable into account.

But the page header does not :
image

It would be nice if it would as well :-)

@BeyondEvil
Copy link
Contributor

Thanks for reporting this! @MaximeWeyl

However, I think this is a limitation (bug?) with pytest itself, and not the plugin. And I'm not really, at least initially, comfortable with solving the symptom.

Thoughts @nicoddemus ?

@nicoddemus
Copy link
Member

Not sure, how does pytest-html get that header?

@BeyondEvil
Copy link
Contributor

Not sure, how does pytest-html get that header?

https://github.com/pytest-dev/pytest-html/blob/master/pytest_html/plugin.py#L435

@nicoddemus

@MaximeWeyl
Copy link
Author

MaximeWeyl commented Apr 25, 2019 via email

@MaximeWeyl
Copy link
Author

MaximeWeyl commented Apr 25, 2019 via email

@nicoddemus
Copy link
Member

addopts does not seem to expand environment variables at all:

[pytest]
addopts = %TEMP%

(I'm on Windows)

Results in:

ERROR: file not found: %TEMP%

Same if I use $TEMP.

As @MaximeWeyl just pointed all, this is the culprit:

class HTMLReport(object):
def __init__(self, logfile, config):
logfile = os.path.expanduser(os.path.expandvars(logfile))
self.logfile = os.path.abspath(logfile)

So this line:

html.h1(os.path.basename(session.config.option.htmlpath)),

Should be using the expanded string as well. 👍

@RibeiroAna
Copy link
Member

I'm not sure I understand, but you want to write the whole path of the test file, not only the tittle, right? Because if is that, you can use just put out the basename thing from it, right? Or am I not seing something?

@BeyondEvil
Copy link
Contributor

addopts does not seem to expand environment variables at all:

Right, as I expected. So this is by design then, and not a bug?

If that's the case, I can create a PR with the suggested fix. :)

@nicoddemus

@BeyondEvil
Copy link
Contributor

I'm not sure I understand, but you want to write the whole path of the test file, not only the tittle, right? Because if is that, you can use just put out the basename thing from it, right? Or am I not seing something?

What's happening is that the environment variable isn't being expanded "in" the report. It's using the name of the env var instead.

@RibeiroAna

@nicoddemus
Copy link
Member

Right, as I expected. So this is by design then, and not a bug?

Exactly. 👍

If that's the case, I can create a PR with the suggested fix. :)

Sure, that would be great!

@BeyondEvil
Copy link
Contributor

So, changing it to use self.logfile with:

addopts = --html $HTMLREP.html where $HTMLREP expands to "hello"

renders the entire path:
Screen Shot 2019-04-26 at 00 37 10

Is that the expected behaviour? 🤔

@nicoddemus @MaximeWeyl

@nicoddemus
Copy link
Member

Sorry, I wasn't clear, the line should be changed to this:

html.h1(os.path.basename(self.logfile)), 

@BeyondEvil
Copy link
Contributor

Sorry, I wasn't clear, the line should be changed to this:

html.h1(os.path.basename(self.logfile)), 

Oh, haha, duh! 😛

I'm going to see if I can add a test for it as well. PR incoming! (Probably not tonight tho..)

@nicoddemus
Copy link
Member

Sure, sounds good! 😁

BeyondEvil added a commit to BeyondEvil/pytest-html that referenced this issue Apr 26, 2019
When the --html flag is used in pytest.ini with "addopts" and the
report title is stored in an environment variable, the name of the
environment variable was used as the report title.

In other words, the environment variable was never expanded.

Fixes: pytest-dev#201
@BeyondEvil
Copy link
Contributor

PR in #203

I would really appreciate it if @MaximeWeyl and/or @nicoddemus could test this also on a Win machine. 🙏

@MaximeWeyl
Copy link
Author

It works !

image

I am on windows 10.

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 a pull request may close this issue.

4 participants