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

Refactor UQ tests #126

Open
mjwen opened this issue Jul 30, 2023 · 6 comments
Open

Refactor UQ tests #126

mjwen opened this issue Jul 30, 2023 · 6 comments

Comments

@mjwen
Copy link
Collaborator

mjwen commented Jul 30, 2023

Hi @yonatank93, in #125 I have refactored the tests to use more recent techniques in pytest to make it easier to maintain and write new tests.

I've slightly tweaked the UQ tests to make it work. But it would be great if you can make a bit more updates.

  • A lot of stuff are not in functions, but in module level (for example, lines 28--70 in this file). Is it possible to move them into functions and call to get them?
  • Related to the above, some of these module level stuff seem to be the same across the four files in the UQ test folder. It would be great if we can make one copy and reuse them? This can be achieved by using a conftest.py file (if placed in the UQ directory, it will only affect tests there).

Let me know if it is unclear and I'd be happy to explain more.

@yonatank93
Copy link
Contributor

yonatank93 commented Jul 30, 2023

  • A lot of stuff are not in functions, but in module level (for example, lines 28--70 in this file). Is it possible to move them into functions and call to get them?

@mjwen Can you tell me which file you are referring to?

@mjwen
Copy link
Collaborator Author

mjwen commented Jul 30, 2023

My bad, forget to insert links. I was referring to test files in this directory: https://github.com/openkim/kliff/tree/master/tests/uq

@yonatank93
Copy link
Contributor

I assume you are referring to, for example, lines 28--79 in test_mcmc.py? Those lines are for getting data to use in mcmc test. I can see it now that there are a lot of overlaps in the setup in test_mcmc.py and test_bootstrap_empirical.py. When I wrote these tests, I wrote them independently. But I can see that we can put all these setups into one file.

If I put them in conftest.py, is there anything else I need to change in the test scripts? Or do I just need to import conftest?

@mjwen
Copy link
Collaborator Author

mjwen commented Jul 30, 2023

Great!

You don't import conftest, but directly use the function names defined in conftest.

You put them in a conftest.py file in the UQ folder, and then use fixture to define them. For example,

@pytest.fixture()
def func1():
     return "aha" 

Then in your actual tests you can pass the function name defined in conftest.py (func1 here) as an argument. For example, in your test_mcmc.py, you can write

test_a_feacture(func1):
   # here func1 will be "aha"

Note, this will only be effective for functions defined with test_* as the function name.

For example, I have defined test_data_dir here, and I can use it anywhere for all tests, e.g. in this function

@yonatank93
Copy link
Contributor

yonatank93 commented Jul 30, 2023

I see. This is a new thing for me. Thanks for telling me about it. I will work on this if you want. I might be slow, though.

@mjwen
Copy link
Collaborator Author

mjwen commented Jul 31, 2023

Thanks! No need to rush at all. Take your time.

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

2 participants