Glad to hear it helped. Following your stuff I was then able to get mine working in about 30 minutes.

I wasn't quite sure where to put test_importer.py since you didn't mention it. Seems to be working in beancount/importers/fidelity/test_importer.py

My beancount/importers/fidelity/__init__.py is empty and the code is beancount/importers/fidelity/fidelity.py Maybe that is why I have ridiculous things like "from importers.fidelity.fidelity import Importer".

On 2024-01-11 9:12 pm, Matt McCormick wrote:

Thanks for the tip about conftest.py. That wasn't mentioned in the documentation. From the link to the past discussion I was able to figure it out and the info about conftest.py was key. Here's my setup now and how it differs from the documentation:

1. The test() function added to myimporter__init__.py is unnecessary. It can be removed.

2. Add `conftest.py` to base directory with the contents

# This adds the --generate option.
# pylint: disable=invalid-name
pytest_plugins = "beancount.ingest.regression_pytest"

3. Don't put your test files in the same directory as the __init__.py file. Otherwise, the tests will attempted to be run on all files, not just files that match identity(). Instead make a sub directory under the importer and place files there.

4. Create a `test_importer.py` file with the following contents:

from pathlib import Path

from beancount.ingest import regression_pytest as regtest

from importers.fidelity import Importer

IMPORTER = Importer()

@regtest.with_importer(IMPORTER)
@regtest.with_testdir(Path(__file__).parent / 'testdata')
class TestImporter(regtest.ImporterTestBase):
pass

In summary, my file directory setup looks like this

beancount/
beancount/my.beancount
beancount/conftest.py

beancount/importers/fidelity/__init__.py  # Importer code
beancount/importers/fidelity/testdata/  # directory for files to test
beancount/importers/fidelity/testdata/my_sample.csv

Then run the following to generate the output files to be used by the tests.

pytest --gen

This will show the tests as skipped.

(venv) $:~/beancount$ pytest --gen
=============================================================================================== test session starts ===============================================================================================
platform linux -- Python 3.10.12, pytest-7.4.4, pluggy-1.3.0
rootdir: /home/matt/beancount
collected 5 items

importers/fidelity/test_importer.py .ssss
========================================================================================== 0 passed, 4 skipped in 0.03s ===========================================================================================

Then run pytest to run the tests.

pytest

(venv) $:~/beancount$ pytest
=============================================================================================== test session starts ===============================================================================================
platform linux -- Python 3.10.12, pytest-7.4.4, pluggy-1.3.0
rootdir: /home/matt/beancount
collected 5 items

importers/fidelity/test_importer.py .....

================================================================================================ 5 passed in 0.03s ================================================================================================

On Thursday 11 January 2024 at 08:26:54 UTC-8 aa...@axvig.com wrote:

I was just working on this same sort of problem (first importer) a couple days ago and haven't gotten back to it, but it felt like I was close. You don't mention a conftest.py file which I think is important. The documentation on this topic is just OK but I can understand why. My next move is to integrate all of the information in this past mailing list discussion: How to use pytests for personal importers / ingest (google.com) [1]

Good luck!

On 2024-01-07 4:18 pm, Matt McCormick wrote:

I'm writing my first importer and trying to generate the test inputs following the instructions here https://beancount.github.io/docs/importing_external_data.html#regression-testing-your-importers

I believe I've followed the instructions but running `pytest` does not generate anything.

I have the following directory structure:

~/beancount/importers/fidelity

~/beancount/importers/fidelity has an __init__.py file with an Importer class that inherits from beancount.ingest.importer.ImporterProtocol

class Importer(ImporterProtocol):
... code

The Importer class implements all the required methods from ImporterProtocol. When I run `bean-extract` I get the output printed to the console.

I've added the test code listed in the document to __init__.py:

def test():
importer = Importer()
yield from regression.compare_sample_files(importer)

When I run pytest I get the following output:

=============================================================================================== test session starts ===============================================================================================
platform linux -- Python 3.10.12, pytest-7.4.4, pluggy-1.3.0
rootdir: /home/matt/beancount/importers/fidelity
collected 0 items

============================================================================================== no tests ran in 0.00s ==============================================================================================

If I run `pytest` from the base beancount directory, it only runs the tests under my price sources module.

Can someone help identify what I may be missing?  Thank you

--
You received this message because you are subscribed to the Google Groups "Beancount" group. To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/cca05bf7-9b0a-4650-8e97-7154c0abb2cen%40googlegroups.com [2].

 --
You received this message because you are subscribed to the Google Groups "Beancount" group. To unsubscribe from this group and stop receiving emails from it, send an email to beancount+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/799dafa6-e927-41ad-87f1-7c15f7ebf403n%40googlegroups.com [3].

Links:
------
[1] https://groups.google.com/g/beancount/c/jH3vIKC7Zq4/m/bNSj-SEeCwAJ
[2] https://groups.google.com/d/msgid/beancount/cca05bf7-9b0a-4650-8e97-7154c0abb2cen%40googlegroups.com?utm_medium=email&utm_source=footer [3] https://groups.google.com/d/msgid/beancount/799dafa6-e927-41ad-87f1-7c15f7ebf403n%40googlegroups.com?utm_medium=email&utm_source=footer

--
You received this message because you are subscribed to the Google Groups 
"Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to beancount+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beancount/f50e8fd3261822af61af4842b9fba06f%40axvig.com.

Reply via email to