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

Shift slow test related pytest hooks in lower level conftest.py #578

Merged
merged 6 commits into from
Jun 8, 2016

Conversation

kdexd
Copy link

@kdexd kdexd commented Jun 2, 2016

There were two primary issues with infrastructure of integration tests developed till now:

  • With the merge of Enable generation of html report of integration tests, and upload to dokuwiki. #570 , the html report was uploaded on dokuwiki. Html report was generated using pytest-html plugin, which requires --html command line option to specify path to save the report locally. But with the help of tempfile module, and also pytest hooks: pytest_configure and pytest_unconfigure declared in top level conftest.py, the report was saved in a temp file, uploaded to dokuwiki and finally deleted.
  • Astropy test helpers were imported as * in top level conftest.py and the configure-unconfigure hooks I declared, actually had overwritten the former ones. This loosened the protection of @remote_data marker provided by astropy test helpers.
    • Fix: All these hooks are moved in lower level conftest.py . It also helps to keep slow tests related hooks and fixtures separate.
  • The plots were saved in /tmp/plots/w7/tardis.__githash__. I used os.rmdir to cleanup the temp directory. But os.rmdir cannot remove non empty directories. Hence running multiple tests successively on same commit required manual deletion of that directory, else the tests would raise OSError.
    • Fix: This directory path was provided using mkdtemp() method of tempfile module. During pytest_unconfigure, recursive deletion was performed using shutil module.

test_method_name = report.nodeid.split('::')[-1]
if test_method_name == "test_spectrum":
# Just making it work for this commit. Will be changes subsequently
with open(os.path.join("/tmp/plots", tardis.__githash__[0:7],
Copy link
Member

Choose a reason for hiding this comment

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

don't use the png file as a workaround - directly encode to base64 binary thingie

@kdexd kdexd force-pushed the html-test-report branch from f7f5854 to 02eaa21 Compare June 3, 2016 05:19
# generated during execution.
tempdir_session = tempfile.mkdtemp()
config.option.tempdir = tempdir_session

html_file = tempfile.NamedTemporaryFile(delete=False)
# Html test report will be generated at this filepath by pytest-html plugin
config.option.htmlpath = html_file.name
Copy link
Author

Choose a reason for hiding this comment

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

A tempdir is added in pytest_configure. Would it be better to declare temporary html file inside tempdir now ?

Copy link
Contributor

Choose a reason for hiding this comment

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

So pytest-html requires config.option.htmlpath to be set to generate a report?
In any case, I'd store the html file handle in the config, too. Then you don't have to worry about deleting the temp file because it should go when config goes out of scope.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, pytest-html plugin wants a filepath (unicode or string) in config.option.htmlpath.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, well I'd say just store the tmpfile in config.option.html

@kdexd kdexd force-pushed the html-test-report branch from 02eaa21 to 6fa9dc6 Compare June 5, 2016 03:15
@kdexd kdexd changed the title [wip] Embed image of spectrum comparison plot in html report. Shift slow test related pytest hooks in lower level conftest.py Jun 5, 2016
@kdexd kdexd force-pushed the html-test-report branch 2 times, most recently from dbe6c33 to 5b11f33 Compare June 5, 2016 04:51
config.option.htmlpath = html_file.name


@remote_data
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure that works and I think that's not how this is supposed to to work.

Copy link
Author

Choose a reason for hiding this comment

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

It is working, here is the report which I generated this morning using this code.

Copy link
Contributor

Choose a reason for hiding this comment

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

and if you remove @remote_data it stops working?
and you have to add --remote-data in the commandline or it won't work?

Copy link
Author

Choose a reason for hiding this comment

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

I have to do both the things simultaneously to make it work.

@yeganer
Copy link
Contributor

yeganer commented Jun 5, 2016

I have some comments on pytest_(un)configure.
I think you should only apply the logic if --integration-tests is provided. If that's the case, it might be a good idea to populate the config during configure and then teardown in unconfigure. You can use the setup from configure in your fixture, too.
I'd preferr request.config instead of pytest.config.

@kdexd kdexd force-pushed the html-test-report branch from 5b11f33 to 04fe4a2 Compare June 5, 2016 07:40
@kdexd kdexd force-pushed the html-test-report branch from 04fe4a2 to d6b97f3 Compare June 5, 2016 08:47
def pytest_unconfigure(config):
# Html report created by pytest-html plugin is read here, uploaded to
# dokuwiki and finally deleted.
if dokuwiki_available:
Copy link
Contributor

Choose a reason for hiding this comment

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

You added a check to pytest_configure to check if we are running the integration tests or not. Please do the same for pytest_unconfigure

@yeganer
Copy link
Contributor

yeganer commented Jun 8, 2016

http://opensupernova.org/~karandesai96/integration/doku.php?id=reports:52115b2 Is the report produced with the latest commit. I'm fine with merging.

@wkerzendorf wkerzendorf merged commit fc0d4e9 into tardis-sn:master Jun 8, 2016
@kdexd kdexd deleted the html-test-report branch June 8, 2016 09:52
ftsamis pushed a commit to ftsamis/tardis that referenced this pull request Nov 12, 2016
…is-sn#578)

* Move slow test related methods to lower level conftest.py

- They conflicted with astropy's test plugins which
  were imported as *.

* Use session wide temp director to store plots.

* Use remote_data marker on pytest_unconfigure.

* Shift unpacking of integration tests config in pytest_configure.

* Cosmetic change - remove unused imports from conftest.py

* Add a check in pytest_unconfigure for integration tests.
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 this pull request may close these issues.

3 participants